postcss-env-function
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/postcss-env-function package

1.0.0 • Public • Published

PostCSS Environment Variables PostCSS Logo

NPM Version Build Status Windows 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 `variables` option is: {
  "--branding-small": "600px",
  "--branding-padding": "20px"
} */

Usage

Add PostCSS Environment Variables to your build tool:

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

Node

Use PostCSS Environment Variables to process your CSS:

import postcssEnvFunction from 'postcss-env-function';

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

PostCSS

Add PostCSS to your build tool:

npm install postcss --save-dev

Use PostCSS Environment Variables as a plugin:

import postcss from 'gulp-postcss';
import postcssEnvFunction from 'postcss-env-function';

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

Webpack

Add PostCSS Loader to your build tool:

npm install postcss-loader --save-dev

Use PostCSS Environment Variables in your Webpack configuration:

import postcssEnvFunction from 'postcss-env-function';

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          { loader: 'css-loader', options: { importLoaders: 1 } },
          { loader: 'postcss-loader', options: {
            ident: 'postcss',
            plugins: () => [
              postcssEnvFunction(/* pluginOptions */)
            ]
          } }
        ]
      }
    ]
  }
}

Gulp

Add Gulp PostCSS to your build tool:

npm install gulp-postcss --save-dev

Use PostCSS Environment Variables in your Gulpfile:

import postcss from 'gulp-postcss';
import postcssEnvFunction from 'postcss-env-function';

gulp.task('css', () => gulp.src('./src/*.css').pipe(
  postcss([
    postcssEnvFunction(/* pluginOptions */)
  ])
).pipe(
  gulp.dest('.')
));

Grunt

Add Grunt PostCSS to your build tool:

npm install grunt-postcss --save-dev

Use PostCSS Environment Variables in your Gruntfile:

import postcssEnvFunction from 'postcss-env-function';

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
  postcss: {
    options: {
      use: [
       postcssEnvFunction(/* pluginOptions */)
      ]
    },
    dist: {
      src: '*.css'
    }
  }
});

Package Sidebar

Install

npm i postcss-env-function@1.0.0

Version

1.0.0

License

CC0-1.0

Unpacked Size

17.5 kB

Total Files

6

Last publish

Collaborators

  • romainmenke
  • alaguna
  • jonathantneal