
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
postcss-modules
Advanced tools
A PostCSS plugin to use CSS Modules everywhere. Not only at the client side.
What is this? For example, you have the following CSS:
/* styles.css */
:global .page {
padding: 20px;
}
.title {
composes: title from "./mixins.css";
color: green;
}
.article {
font-size: 16px;
}
/* mixins.css */
.title {
color: black;
font-size: 40px;
}
.title:hover {
color: red;
}
After the transformation it will become like this:
._title_116zl_1 {
color: black;
font-size: 40px;
}
._title_116zl_1:hover {
color: red;
}
.page {
padding: 20px;
}
._title_xkpkl_5 {
color: green;
}
._article_xkpkl_10 {
font-size: 16px;
}
And the plugin will give you a JSON object for transformed classes:
{
"title": "_title_xkpkl_5 _title_116zl_1",
"article": "_article_xkpkl_10",
}
By default, a JSON file with exported classes will be placed next to corresponding CSS.
But you have a freedom to make everything you want with exported classes, just
use the getJSON callback. For example, save data about classes into a corresponding JSON file:
postcss([
require('postcss-modules')({
getJSON: function(cssFileName, json) {
var path = require('path');
var cssName = path.basename(cssFileName, '.css');
var jsonFileName = path.resolve('./build' + cssName + '.json');
fs.writeFileSync(jsonFileName, JSON.stringify(json));
}
});
]);
Generate custom classes with the generateScopedName callback:
postcss([
require('postcss-modules')({
generateScopedName: function(name, filename, css) {
var path = require('path');
var i = css.indexOf('.' + name);
var numLines = css.substr(0, i).split(/[\r\n]/).length;
var file = path.basename(filename, '.css');
return '_' + file + '_' + numLines + '_' + name;
}
});
]);
See PostCSS docs for examples for your environment and don't forget to run
npm install --save-dev postcss-modules
0.3.0
css-loader is a webpack loader that interprets @import and url() like import/require() and will resolve them. It also offers modules functionality similar to postcss-modules, where it localizes CSS by default using similar scoping rules. Compared to postcss-modules, css-loader is tightly integrated with webpack's module system, which might be preferable in webpack-based projects.
styled-components is a library for React and React Native that allows CSS to be written inside JavaScript files by tagging template literals. This approach scopes styles by generating unique class names at runtime. Unlike postcss-modules, styled-components embeds styles directly into components, which can enhance runtime performance and offers enhanced theming capabilities.
FAQs
PostCSS plugin to use CSS Modules everywhere
The npm package postcss-modules receives a total of 1,762,773 weekly downloads. As such, postcss-modules popularity was classified as popular.
We found that postcss-modules demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.