Gathering detailed insights and metrics for postcss-modules-values-replace
Gathering detailed insights and metrics for postcss-modules-values-replace
Gathering detailed insights and metrics for postcss-modules-values-replace
Gathering detailed insights and metrics for postcss-modules-values-replace
PostCSS plugin intended to replace CSS Modules values
npm install postcss-modules-values-replace
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
20 Stars
115 Commits
9 Forks
1 Watching
1 Branches
7 Contributors
Updated on 08 Jul 2024
JavaScript (97.93%)
CSS (2.07%)
Cumulative downloads
Total Downloads
Last day
-6.4%
34,660
Compared to previous day
Last week
23%
174,279
Compared to previous week
Last month
74.5%
664,139
Compared to previous month
Last year
116.5%
4,589,240
Compared to previous year
1
4
PostCSS plugin to work around CSS Modules values limitations.
Replaces CSS Modules @values just as postcss-modules-values does, but without help of css-loader, so it could be used before other PostCSS plugins like postcss-calc.
Example:
1/* constants.css */ 2@value unit: 8px; 3@value footer-height: calc(unit * 5); 4 5/* my-components.css */ 6@value unit, footer-height from "./constants.css"; 7@value component-height: calc(unit * 10); 8 9.my-component { 10 padding: unit; 11 margin-top: footer-height; 12 height: component-height; 13}
yields my-components.css
:
1 @value unit, footer-height from "./constants.css"; 2 @value component-height: calc(8px * 10); 3 4 .my-component { 5 padding: 8px; 6 margin-top: calc(8px * 5); 7 height: calc(8px * 10); 8 }
and leads to export of following values to JS:
1{ 2 "unit": "8px", 3 "footer-height": "calc(8px * 5)", 4 "component-height": "calc(8px * 10)", 5 ... 6}
See how to export computed values in usage with calc
example below.
Place it before other plugins:
1postcss([ require('postcss-modules-values-replace'), require('postcss-calc') ]);
When using from webpack, pass its file system in postcss.config.js
form:
1module.exports = (ctx) => ({ 2 plugins: [ 3 require('postcss-modules-values-replace')({fs: ctx.webpack._compiler.inputFileSystem}), 4 require('postcss-calc'), 5 ] 6});
See PostCSS docs for other examples for your environment.
Object
File system to use. To make it faster in webpack pass its file system to plugin. Cached Node's file system is used by default.
Object
enhanced-resolve's configuration object, see there for possible options and defaults.
boolean
When enabled @value rules/declarations will be removed from the emitted output
Input:
1@value myBrandColor blue; 2@font-face {} 3 4body { background: myBrandColor }
Output:
1@font-face {} 2 3body { background: blue }
boolean
When enabled, permit plugins defined earlier in the PostCSS pipeline to modify @value
declarations before they are recorded by this plugin.
boolean
When enabled, value imports will be resolved as module requests, in line with css-loader
's resolution logic as of 2.0.0.
If your code is written with pre-2.0 import syntax, and utilises postcss-modules-tilda for compatibility, this option is not required.
boolean
When enabled, value usage within rule selectors will also be replaced by this plugin.
Array<string>
You can pass a list of at-rules in which @value
's should be replaced. Only @media
rules will be processed by default.
Note that passed array isn't merged with default ['media']
but overwrites it, so you'll need to include all the rules you want to be processed.
1postcss([ 2 require('postcss-modules-values-replace')({ atRules: ['media', 'container'] }) 3]);
Input:
1@value $tables from './breakpoints.css'; 2 3@container (width >= $tablet) {}
Output:
1@container (width >= 768px) {}
To enable calculations inside @value, enable media queries support in postcss-calc:
1postcss([ 2 require('postcss-modules-values-replace'), 3 require('postcss-calc')({mediaQueries: true}) 4])
or via postcss-cssnext:
1postcss([ 2 require('postcss-modules-values-replace'), 3 require('postcss-cssnext')({features: {calc: {mediaQueries: true}}}) 4])
Example with calc
enabled:
1/* constants.css */ 2@value unit: 8px; 3@value footer-height: calc(unit * 5); 4 5/* my-components.css */ 6@value unit, footer-height from "./constants.css"; 7@value component-height: calc(unit * 10); 8 9.my-component { 10 padding: unit; 11 margin-top: footer-height; 12 height: component-height; 13}
yields my-components.css
:
1 @value unit, footer-height from "./constants.css"; 2 @value component-height: 80px; 3 4 .my-component { 5 padding: 8px; 6 margin-top: 40px; 7 height: 80px; 8 }
and leads to export of following values to JS:
1{ 2 "unit": "8px", 3 "footer-height": "40px", 4 "component-height": "80px", 5 ... 6}
postcss-calc and postcss-color-function are known to work inside @value as they traverse media queries. Experience with other plugins may differ if they ignore media queries.
This plugin provides to postcss a custom messages object with type: 'values'
.
The values
property of that object will contain all the extracted values with all substitution performed (i.e. for values that reference other values).
See modules-values-extract for an example of how this can be used.
Node.js 6.5 or above is recomended.
ISC
Code is mostly taken from postcss-modules-values by Glen Maddern, Mark Dalgleish and other contributors.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 1/5 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More