Skip to content

Commit 550274e

Browse files
mrchiefJack Zhaoiansu
committed
Adds PostCSS Normalize (#5810)
* Add postcss-normalize plugin * Configure PostCSS Normalize * Add documentation * Include the doc in sidebar * Fix the id in sidebar.json * Update adding-css-reset.md Co-authored-by: Jack Zhao <[email protected]> Co-authored-by: Ian Sutherland <[email protected]>
1 parent ffcd896 commit 550274e

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

docusaurus/docs/adding-css-reset.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
id: adding-css-reset
3+
title: Adding a CSS Reset
4+
sidebar_label: Adding CSS Reset
5+
---
6+
7+
This project setup uses [PostCSS Normalize] for adding a [CSS Reset].
8+
9+
To start using it, add `@import-normalize;` anywhere in your CSS file(s). You only need to include it once and duplicate imports are automatically removed. Since you only need to include it once, a good place to add it is `index.css` or `App.css`.
10+
11+
## `index.css`
12+
13+
```css
14+
@import-normalize; /* bring in normalize.css styles */
15+
16+
/* rest of app styles */
17+
```
18+
19+
You can control which parts of [normalize.css] to use via your project's [browserslist].
20+
21+
Results when [browserslist] is `last 3 versions`:
22+
23+
```css
24+
/**
25+
* Add the correct display in IE 9-.
26+
*/
27+
28+
audio,
29+
video {
30+
display: inline-block;
31+
}
32+
33+
/**
34+
* Remove the border on images inside links in IE 10-.
35+
*/
36+
37+
img {
38+
border-style: none;
39+
}
40+
```
41+
42+
Results when [browserslist] is `last 2 versions`:
43+
44+
```css
45+
/**
46+
* Remove the border on images inside links in IE 10-.
47+
*/
48+
49+
img {
50+
border-style: none;
51+
}
52+
```
53+
54+
## Browser support
55+
56+
Browser support is dictated by what normalize.css [supports]. As of this writing, it includes:
57+
58+
- Chrome (last 3)
59+
- Edge (last 3)
60+
- Firefox (last 3)
61+
- Firefox ESR
62+
- Opera (last 3)
63+
- Safari (last 3)
64+
- iOS Safari (last 2)
65+
- Internet Explorer 9+
66+
67+
[browserslist]: http://browserl.ist/
68+
[css reset]: https://cssreset.com/what-is-a-css-reset/
69+
[normalize.css]: https://github.com/csstools/normalize.css
70+
[supports]: https://github.com/csstools/normalize.css#browser-support
71+
[postcss normalize]: https://github.com/csstools/postcss-normalize

docusaurus/website/sidebars.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"adding-a-stylesheet",
1919
"adding-a-css-modules-stylesheet",
2020
"adding-a-sass-stylesheet",
21+
"adding-css-reset",
2122
"post-processing-css",
2223
"adding-images-fonts-and-files",
2324
"loading-graphql-files",

packages/react-scripts/config/webpack.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
3535
// @remove-on-eject-begin
3636
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
3737
// @remove-on-eject-end
38+
const postcssNormalize = require('postcss-normalize');
3839

3940
// Source maps are resource heavy and can cause out of memory issue for large source files.
4041
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
@@ -108,6 +109,10 @@ module.exports = function(webpackEnv) {
108109
},
109110
stage: 3,
110111
}),
112+
// Adds PostCSS Normalize as the reset css with default options,
113+
// so that it honors browserslist config in package.json
114+
// which in turn let's users customize the target behavior as per their needs.
115+
postcssNormalize(),
111116
],
112117
sourceMap: isEnvProduction && shouldUseSourceMap,
113118
},

packages/react-scripts/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"pnp-webpack-plugin": "1.2.1",
6060
"postcss-flexbugs-fixes": "4.1.0",
6161
"postcss-loader": "3.0.0",
62+
"postcss-normalize": "7.0.1",
6263
"postcss-preset-env": "6.6.0",
6364
"postcss-safe-parser": "4.0.1",
6465
"react-app-polyfill": "^0.2.2",

0 commit comments

Comments
 (0)