postcss-css-variables
Advanced tools
Comparing version
# v0.9.0 - 2018-6-26 | ||
- Adds `opts.preserveInjectedVariables`, which when set to `false`, removes the `:root { ... }` custom property declarations added via `opts.variables` | ||
- Thank you to [@akdetrick](https://github.com/akdetrick) for the [contribution](https://github.com/MadLittleMods/postcss-css-variables/pull/74) | ||
# v0.8.1 - 2018-3-21 | ||
@@ -3,0 +9,0 @@ |
19
index.js
@@ -65,3 +65,6 @@ // PostCSS CSS Variables (postcss-css-variables) | ||
// or an object with a `value` property and an optional `isImportant` bool property | ||
variables: {} | ||
variables: {}, | ||
// Preserve variables injected via JS with the `variables` option above | ||
// before serializing to CSS (`false` will remove these variables from output) | ||
preserveInjectedVariables: true | ||
}; | ||
@@ -86,2 +89,6 @@ | ||
// Keep track of the injected from `opts.variables` to remove at the end | ||
// if user passes `opts.preserveInjectedVariables = false` | ||
var injectedDeclsToRemoveAtEnd = []; | ||
// Map of variable names to a list of declarations | ||
@@ -111,2 +118,7 @@ var map = {}; | ||
// Collect JS-injected variables for removal if `opts.preserveInjectedVariables = false` | ||
if (!opts.preserveInjectedVariables) { | ||
injectedDeclsToRemoveAtEnd.push(varDecl); | ||
} | ||
// Add the entry to the map | ||
@@ -255,3 +267,8 @@ prevVariableMap[variableName] = (prevVariableMap[variableName] || []).concat({ | ||
// Clean up JS-injected variables marked for removal | ||
injectedDeclsToRemoveAtEnd.forEach(function(injectedDecl) { | ||
injectedDecl.remove(); | ||
}); | ||
//console.log('map', map); | ||
@@ -258,0 +275,0 @@ |
{ | ||
"name": "postcss-css-variables", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"description": "PostCSS plugin to transform CSS Custom Properties(CSS variables) syntax into a static representation", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -371,3 +371,10 @@ # PostCSS CSS Variables | ||
### `preserveInjectedVariables` (default: `true`) | ||
Whether to preserve the custom property declarations inserted via the `variables` option from final output. | ||
A typical use case is [CSS Modules](https://github.com/css-modules/css-modules), where you would want to avoid | ||
repeating custom property definitions in every module passed through this plugin. Setting this option to `false` | ||
prevents JS-injected variables from appearing in output CSS. | ||
```js | ||
@@ -374,0 +381,0 @@ var postcss = require('postcss'); |
55449
2.59%815
1.75%422
1.69%19
-5%