JSPM

postcss-var-func-fallback

3.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2478
  • Score
    100M100P100Q124725F
  • License MIT

PostCSS plugin Adds fallback values to var(name) occurences.

Package Exports

  • postcss-var-func-fallback
  • postcss-var-func-fallback/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (postcss-var-func-fallback) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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)