Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

postcss-env-function

Package Overview
Dependencies
1
Maintainers
2
Versions
12
Issues
File Explorer

Advanced tools

postcss-env-function

Use env() variables in CSS

    4.0.6latest

Version published
Maintainers
2
Weekly downloads
6,796,400
decreased by-9.97%

Weekly downloads

Readme

Source

PostCSS Environment Variables PostCSS Logo

NPM Version CSS Standard Status Build Status Discord

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 postcss-env-function --save-dev

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:

NodePostCSS CLIWebpackCreate React AppGulpGrunt

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.

postcssEnvFunction({ 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 environment-variables key.

postcssEnvFunction({ importFrom: [ /* Import from a CommonJS file: module.exports = { environmentVariables: { '--branding-padding': '20px' } } */ 'path/to/file.js', /* Import from a JSON file: { "environment-variables": { "--branding-padding": "20px" } } */ 'and/then/this.json', /* Import from an JavaScript Object: */ { environmentVariables: { '--branding-padding': '20px' } }, /* Import from a JavaScript Function: */ () => { const environmentVariables = { '--branding-padding': '20px' } return { environmentVariables } } ] })

See example imports written in JS and JSON. Currently only valid custom property names (beginning with --) are accepted. Not all valid declaration value names are accepted.

disableDeprecationNotice

Silence the deprecation notice that is printed to the console when using `importFrom``.

postcss-env-function is deprecated and will be removed. Check the discussion on github for more details. https://github.com/csstools/postcss-plugins/discussions/192

Keywords

FAQs

What is postcss-env-function?

Use env() variables in CSS

Is postcss-env-function popular?

The npm package postcss-env-function receives a total of 6,424,908 weekly downloads. As such, postcss-env-function popularity was classified as popular.

Is postcss-env-function well maintained?

We found that postcss-env-function demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 2 open source maintainers collaborating on the project.

Last updated on 19 Mar 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc