# PostCSS Environment Variables

[![NPM Version](https://img.shields.io/npm/v/postcss-env-function.svg)](https://www.npmjs.com/package/postcss-env-function) [![CSS Standard Status](https://cssdb.org/badge/environment-variables.svg)](https://cssdb.org/#environment-variables) [![Build Status](https://img.shields.io/travis/jonathantneal/postcss-env-function.svg)](https://travis-ci.org/jonathantneal/postcss-env-function) [![Support Chat](https://img.shields.io/badge/support-chat-blue.svg)](https://gitter.im/postcss/postcss)

[PostCSS Environment Variables](https://github.com/jonathantneal/postcss-env-function) lets you use `env()` variables in CSS, following the [CSS Environment Variables](https://drafts.csswg.org/css-env-1/) 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](https://github.com/jonathantneal/postcss-env-function) to your project:

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

Use [PostCSS Environment Variables](https://github.com/jonathantneal/postcss-env-function) to process your CSS:

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

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

Or use it as a [PostCSS](https://github.com/postcss/postcss) plugin:

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

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

[PostCSS Environment Variables](https://github.com/jonathantneal/postcss-env-function) runs in all Node environments, with special instructions for:

| [Node](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-env-function/INSTALL.md#node) | [PostCSS CLI](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-env-function/INSTALL.md#postcss-cli) | [Webpack](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-env-function/INSTALL.md#webpack) | [Create React App](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-env-function/INSTALL.md#create-react-app) | [Gulp](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-env-function/INSTALL.md#gulp) | [Grunt](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-env-function/INSTALL.md#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.

```js
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.

```js
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](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-env-function/test/import-variables.js) and [JSON](https://github.com/bgoonz/Learning-Redux/blob/master/repos/examples/real-world/node_modules/postcss-env-function/test/import-variables.json).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bryan-guner.gitbook.io/my-docs/redux/repos/examples/real-world/node_modules/postcss-env-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
