Skip to content

Commit 7dcaf45

Browse files
Dan503ai
authored andcommitted
Adding better environment variables documentation (#1261)
The documentation now gives a step by step guide on how to use environment variables to turn on CSS Grid prefixing. I've also added it to the table of contents.
1 parent bf2e89e commit 7dcaf45

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Twitter account for news and releases: [@autoprefixer].
9595
- [Warnings](#warnings)
9696
- [Disabling](#disabling)
9797
- [Options](#options)
98+
- [Environment variables](#environment-variables)
99+
- [Using environment variables to support CSS Grid prefixes in Create React App](#using-environment-variables-to-support-css-grid-prefixes-in-create-react-app)
98100
- [Grid Autoplacement support in IE](#grid-autoplacement-support-in-ie)
99101
- [Debug](#debug)
100102

@@ -622,16 +624,48 @@ to increase performance.
622624
* `no-autoplace`: enable Autoprefixer grid translations
623625
but *exclude* autoplacement support.
624626

625-
Environment variables is useful, when you can change Autoprefixer options.
626-
For instance, in Create React App.
627+
Environment variables are useful, when you want to change Autoprefixer options but don't have access to config files.
628+
[Create React App] is a good example of this.
627629

628-
Add variable before CLI command, which will build your CSS:
630+
[Create React App]: (https://reactjs.org/docs/create-a-new-react-app.html#create-react-app)
629631

630-
```sh
631-
AUTOPREFIXER_GRID=autoplace npm build
632+
### Using environment variables to support CSS Grid prefixes in Create React App
633+
634+
1. Run the command `npm install autoprefixer@latest`
635+
2. Under `"browserslist"` > `"development"` in the package.json file, add `"last 1 ie version"`
636+
637+
```
638+
"browserslist": {
639+
"production": [
640+
">0.2%",
641+
"not dead",
642+
"not op_mini all"
643+
],
644+
"development": [
645+
"last 1 chrome version",
646+
"last 1 firefox version",
647+
"last 1 safari version",
648+
"last 1 ie version"
649+
]
650+
}
632651
```
633652

634-
See also [Browserslist environment variables].
653+
3. Update `"scripts"` in the package.json file to the following:
654+
655+
```
656+
"scripts": {
657+
"start": "set AUTOPREFIXER_GRID=autoplace && react-scripts start",
658+
"build": "set AUTOPREFIXER_GRID=autoplace && react-scripts build",
659+
"test": "set AUTOPREFIXER_GRID=autoplace && react-scripts test",
660+
"eject": "react-scripts eject"
661+
},
662+
```
663+
664+
Replace `autoplace` with `no-autoplace` in the above example if you prefer to disable Autoprefixer Grid autoplacement support.
665+
666+
Now when you run `npm start` you will see CSS Grid prefixes automatically being applied to your output CSS.
667+
668+
See also [Browserslist environment variables] for more examples on how to use environment variables in your project.
635669

636670
[Browserslist environment variables]: https://github.com/browserslist/browserslist#environment-variables
637671

0 commit comments

Comments
 (0)