![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
postcss-modules-scope
Advanced tools
Package description
The postcss-modules-scope npm package is a PostCSS plugin that helps in locally scoping CSS by automatically renaming classes and other identifiers to be unique. This ensures that styles do not conflict across different parts of an application. It is commonly used in modular CSS architecture.
Local Scoping of CSS Classes
This feature automatically renames CSS classes to include a unique identifier, preventing class name collisions.
/* Input CSS */
.className {
color: red;
}
/* Output CSS after processing with postcss-modules-scope */
._className_1a2b3c {
color: red;
}
Renaming of Animation Names
This feature renames animation names with a unique identifier to avoid conflicts with other animations in the global scope.
/* Input CSS */
@keyframes myAnimation {
from { opacity: 0; }
to { opacity: 1; }
}
/* Output CSS after processing with postcss-modules-scope */
@keyframes myAnimation_1a2b3c {
from { opacity: 0; }
to { opacity: 1; }
}
css-loader is a webpack loader that interprets `@import` and `url()` like `import/require()` and will resolve them. It also offers modules functionality that allows for local scoping of CSS by default, similar to what postcss-modules-scope provides.
postcss-modules is another PostCSS plugin that goes beyond scoping and also tracks the CSS dependencies and exports the generated identifiers. It provides a more integrated solution for working with CSS modules.
postcss-preset-env is a plugin that allows you to use future CSS features today. It includes cssdb-compliant plugins that convert modern CSS into something most browsers can understand, ensuring that features are only polyfilled as needed. It doesn't provide CSS modules functionality directly but can be used in conjunction with other modules plugins.
Readme
Transforms:
:local(.continueButton) {
color: green;
}
into:
:export {
continueButton: __buttons_continueButton_djd347adcxz9;
}
.__buttons_continueButton_djd347adcxz9 {
color: green;
}
so it doesn't pollute CSS global scope and can be simply used in JS like so:
import styles from './buttons.css'
elem.innerHTML = `<button class="${buttons.continueButton}">Continue</button>`
Since we're exporting class names, there's no reason to export only one. This can give us some really useful reuse of styles:
.globalButtonStyle {
background: white;
border: 1px solid;
border-radius: 0.25rem;
}
.globalButtonStyle:hover {
box-shadow: 0 0 4px -2px;
}
:local(.continueButton) {
composes: globalButtonStyle;
color: green;
}
becomes:
.globalButtonStyle {
background: white;
border: 1px solid;
border-radius: 0.25rem;
}
.globalButtonStyle:hover {
box-shadow: 0 0 4px -2px;
}
:local(.continueButton) {
extends: globalButtonStyle;
color: green;
}
You're looking for CSS Modules. It spans this plugin as well as a few others, and it's amazing.
npm install
npm build
npm test
npm watch
will watch src
for changes and rebuildnpm autotest
will watch src
and test
for changes and retestISC
Glen Maddern, 2015.
FAQs
A CSS Modules transform to extract export statements from local-scope classes
The npm package postcss-modules-scope receives a total of 14,107,837 weekly downloads. As such, postcss-modules-scope popularity was classified as popular.
We found that postcss-modules-scope demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers 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.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.