JSPM

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

PostCSS plugin cleans up the variable names and saves space. It can will reduce your css variable to smaller variables

Package Exports

  • postcss-variable-compress
  • postcss-variable-compress/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-variable-compress) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

PostCSS Variable Compress npm GitHub branch checks state

postcss-variable-compress is a PostCSS plugin minifies variable names and saves space. Even if you have 1295 css variables still they will not exceed by two characters. It will transform css variable without breaking your stylesheet. Get if from NPM.

If you want it not modify some css variables, then pass them --{variable-name} as an array to the plugin.

If you are looking for a plugin that can work on separate files go to import splitFiles.js, works the same but it doesn't resets the variables.

:root {
  --first-color: #16f;
  --second-color: #ff7;
}

#firstParagraph {
  background-color: var(--first-color);
  color: var(--second-color);
}

#container {
  --first-color: #290;
}
:root {
  --0: #16f;
  --1: #ff7;
}

#firstParagraph {
  background-color: var(--0);
  color: var(--1);
}

#container {
  --0: #290;
}

Usage

Step 1: Install plugin:

npm install --save-dev postcss postcss-variable-compress

Step 2: Check you project for existed 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 at the end of the plugins list:

module.exports = {
  plugins: [
    require('cssnano'),
+   require('postcss-variable-compress')
  ]
}

Api

module.exports = {
  plugins: [
    require('cssnano'),
    require('postcss-variable-compress')(
      // pass in css variables to avoid
      'light', 'dark', 'font', 'vh', 'r' // unprefixed
      // or
      '--height', '--font' // prefixed
      // or pass in as many function as your want
      // they take single param which is a the name of css variable
      // you can do checks on it and
      // return true if you want it to be skipped
      // for example
      (name) => name.includes('skip') // name prefixed css variable example --height
      // avoid regex if you can they are bad
    )
  ]
}