postcss-modules-scope
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/postcss-modules-scope package

3.2.1 • Public • Published

CSS Modules: Scope Locals & Extend

Build Status

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="${styles.continueButton}">Continue</button>`;

Composition

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) {
  compose-with: globalButtonStyle;
  color: green;
}

becomes:

.globalButtonStyle {
  background: white;
  border: 1px solid;
  border-radius: 0.25rem;
}
.globalButtonStyle:hover {
  box-shadow: 0 0 4px -2px;
}
:local(.continueButton) {
  compose-with: globalButtonStyle;
  color: green;
}

Note: you can also use composes as a shorthand for compose-with

Local-by-default & reuse across files

You're looking for CSS Modules. It uses this plugin as well as a few others, and it's amazing.

Building

npm install
npm test
  • Status: Build Status
  • Lines: Coverage Status
  • Statements: codecov.io

Development

  • npm test:watch will watch src and test for changes and run the tests

License

ISC

With thanks

  • Mark Dalgleish
  • Tobias Koppers
  • Guy Bedford

Glen Maddern, 2015.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.0-beta10beta
3.2.15,915,882latest
3.0.0-rc.23next

Version History

VersionDownloads (Last 7 Days)Published
3.2.15,915,882
3.2.03,170,551
3.1.23,556
3.1.1654,232
3.1.0126,063
3.0.03,665,051
3.0.0-rc.23
3.0.0-rc.12
3.0.0-rc.00
2.2.02,783,998
2.1.171,996
2.1.093,032
2.0.16,413
2.0.02
1.1.0982,246
1.0.24,599
1.0.121
1.0.060
1.0.0-beta21,398
1.0.0-beta10
0.0.82,227
0.0.75
0.0.62
0.0.50
0.0.41
0.0.324
0.0.20
0.0.11

Package Sidebar

Install

npm i postcss-modules-scope

Weekly Downloads

17,481,365

Version

3.2.1

License

ISC

Unpacked Size

17.5 kB

Total Files

5

Last publish

Collaborators

  • markdalgleish
  • sokra
  • geelen
  • evilebottnawi