JSPM

postcss-inject-css-variables

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 199
  • Score
    100M100P100Q94578F
  • License WTFPL

Inject global CSS variables into your files via PostCSS

Package Exports

  • postcss-inject-css-variables

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-inject-css-variables) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

PostCSS Inject CSS Variables Build Status

Inject global CSS variables into your files via PostCSS

Transform

/* Your CSS */

to

:root {
  --colorAlpha: #000;
  --colorBeta: #111
}
/* Your CSS */

using

module.exports = {
  colorAlpha: '#000',
  colorBeta: '#111'
}

and some PostCSS magic

Installation

npm i -D postcss-inject-css-variables

Usage

with node

const postcss = require('postcss')
const injectVariables = require('postcss-inject-css-variables')

const fs = require('fs')

const mycss = fs.readFileSync('input.css', 'utf8')

const variables = {
  colorAlpha: '#000',
  colorBeta: '#111'
}

// Process your CSS with postcss-inject-css-variables
const output = postcss([
    injectVariables(variables)
  ])
  .process(mycss)
  .css

console.log(output)

// :root {
//   --colorAlpha: #000;
//   --colorBeta: #111
// }
// /* CSS content */

with webpack

webpack.config.js

const variables = require('./variables.js')

const config = {
  postcss: function (webpack) {
    return [
      // plugins..
      require('postcss-inject-css-variables')(variables),
      // more plugins..
    ]
  },
}

variables.js

module.exports = {
  colorAlpha: '#000',
  colorBeta: '#111'
}

License

Copyright © 2016 Pierre Cholhot <hello@pierre.cx>

This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2,
as published by Sam Hocevar. See the LICENSE file for more details.