postcss-var-func-fallback
v3.0.0
Published
PostCSS plugin Adds fallback values to var(name) occurences.
Downloads
4,117
Maintainers
Readme
PostCSS var() fallback
PostCSS plugin Adds fallback values to var(name) occurences.
.foo {
/* Input example */
color: var(--theme);
}
.foo {
/* Output example */
color: var(--theme, royalblue);
}
Usage
Step 1: Install plugin:
npm install --save-dev postcss postcss-var-func-fallback
Step 2: Check your project for existing PostCSS config: postcss.config.js
in the project root, "postcss"
section in package.json
or postcss
in bundle config.
If you do not use PostCSS, add it according to official docs and set this plugin in settings.
Step 3: Add the plugin to plugins list:
module.exports = {
plugins: [
+ require('postcss-var-func-fallback')({
+ variables: {
+ '--theme': 'royalblue'
+ }
+ }),
require('autoprefixer')
]
}
Options
variables
(default: {}
)
An object map of variable declarations in JavaScript that will be used to complement var(name) occurences with fallback values.
treatErrorsAsWarnings
(default: false
)
If set to true
, known errors will be printed as warnings instead of throwing an Exception.
Notes
- This plugin fits well when having external css-variable declarations (see get-css-variables plugin for extracting an object map)
- This plugin don't solve IE11 support (see postcss-css-variables plugin)