This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
TripSit_Suite/node_modules/postcss-env-function
cranberry ed23347e56 Initial comission of TheLounge base files 2020-11-01 22:46:04 +00:00
..
node_modules Initial comission of TheLounge base files 2020-11-01 22:46:04 +00:00
CHANGELOG.md Initial comission of TheLounge base files 2020-11-01 22:46:04 +00:00
LICENSE.md Initial comission of TheLounge base files 2020-11-01 22:46:04 +00:00
README.md Initial comission of TheLounge base files 2020-11-01 22:46:04 +00:00
index.cjs.js Initial comission of TheLounge base files 2020-11-01 22:46:04 +00:00
index.cjs.js.map Initial comission of TheLounge base files 2020-11-01 22:46:04 +00:00
index.es.mjs Initial comission of TheLounge base files 2020-11-01 22:46:04 +00:00
index.es.mjs.map Initial comission of TheLounge base files 2020-11-01 22:46:04 +00:00
package.json Initial comission of TheLounge base files 2020-11-01 22:46:04 +00:00

README.md

PostCSS Environment Variables PostCSS Logo

NPM Version CSS Standard Status Build Status Support Chat

PostCSS Environment Variables lets you use env() variables in CSS, following the CSS Environment Variables specification.

@media (max-width: env(--branding-small)) {
  body {
    padding: env(--branding-padding);
  }
}

/* becomes */

@media (min-width: 600px) {
  body {
    padding: 20px;
  }
}

/* when the `importFrom` option is: {
  "environmentVariables": {
    "--branding-small": "600px",
    "--branding-padding": "20px"
  }
} */

Usage

Add PostCSS Environment Variables to your project:

npm install postcss-env-function --save-dev

Use PostCSS Environment Variables to process your CSS:

const postcssEnvFunction = require('postcss-env-function');

postcssEnvFunction.process(YOUR_CSS /*, processOptions, pluginOptions */);

Or use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssEnvFunction = require('postcss-env-function');

postcss([
  postcssEnvFunction(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

PostCSS Environment Variables runs in all Node environments, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt

Options

importFrom

The importFrom option specifies sources where Environment Variables can be imported from, which might be JS and JSON files, functions, and directly passed objects.

postcssCustomProperties({
  importFrom: 'path/to/file.js' /* module.exports = {
      environmentVariables: {
        '--branding-padding': '20px',
        '--branding-small': '600px'
      }
    } */
});
@media (max-width: env(--branding-small)) {
  body {
    padding: env(--branding-padding);
  }
}

/* becomes */

@media (min-width: 600px) {
  body {
    padding: 20px;
  }
}

Multiple sources can be passed into this option, and they will be parsed in the order they are received. JavaScript files, JSON files, functions, and objects will need to namespace Custom Properties using the environmentVariables or variables-variables key.

postcssCustomProperties({
  importFrom: [
    'path/to/file.js', // module.exports = { environmentVariables: { '--branding-padding': '20px' } }
    'and/then/this.json', // { "environment-variables": { "--branding-padding": "20px" } }
    {
      environmentVariables: { '--branding-padding': '20px' }
    },
    () => {
      const environmentVariables = { '--branding-padding': '20px' };

      return { environmentVariables };
    }
  ]
});

See example imports written in JS and JSON.