This package has been deprecated

Author message:

WARNING: This project has been renamed to postcss-constants. Install using postcss-constants instead.

postcss-local-constants

0.1.0 • Public • Published

PostCSS Local Constants Build Status

PostCSS plugin to process imported constants from a file, removing them from a global scope.

constants.js

module.exports = {
  colors: {
    primary: '#8EE7D3',
  },
};

input

~colors: "./constants.js";
.foo {
  color: ~colors.primary;
}

output

.foo {
  color: #8EE7D3;
}

Within static values

constants.js

module.exports = {
  borders: {
    weight: '2px',
    style: 'solid',
  },
};

input

~borders: "./constants.js";
.foo {
  border: ~borders.weight ~borders.style black;
}

output

.foo {
  border: 2px solid black;
}

@ Rules

constants.js

module.exports = {
  queries: {
    maxWidth: '200px',
  },
}

input

~queries: "./constants.js";
 
@media (max-width: ~queries.maxWidth) {
  color: blue;
}

output

@media (max-width: 200px) {
  color: blue;
}

Usage

postcss([ require('postcss-local-constants') ])

You can pass a default set of constants (that can be overriden), if you want to update default constants in webpack hot reload:

postcss([
  localConsts({
    defaults: {
      colors: {
        primary: 'blue',
      },
    }
  })
])

Call postcss-local-constants before any plugins that will compute values stored in constants. See PostCSS docs for examples for your environment.

Package Sidebar

Install

npm i postcss-local-constants

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • ojame