postcss-var-func-fallback
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

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)

/postcss-var-func-fallback/

    Package Sidebar

    Install

    npm i postcss-var-func-fallback

    Weekly Downloads

    2,659

    Version

    3.0.1

    License

    MIT

    Unpacked Size

    6.21 kB

    Total Files

    5

    Last publish

    Collaborators

    • dvitamin