Convert Material UI icons to path imports. E.g.
-import { ErrorOutline as ErrorIcon } from "@material-ui/icons";
+import ErrorIcon from "@material-ui/icons/ErrorOutline";
Reasoning:-
- This reduces development time as react-scripts is faster to start and smaller bundle sizes.
- Any icon not imported in this fashion has the side effect of the entire icon library being imported.
- Production builds i.e.
react-scripts build
are not affected as treeshaking occurs normally.
jscodeshift -v 2 -t ./transform.js src
Development bundle sizes before and after conversion to path imports.
└── [ 160] before
| ├── [ 19M] 0.chunk.js
| ├── [ 35K] bundle.js
| └── [1.5M] main.chunk.js
├── [ 160] after
├── [9.3M] 0.chunk.js
├── [ 35K] bundle.js
└── [1.5M] main.chunk.js
21M vs 11M difference.
Before
yarn start 0.21s user 0.04s system 1% cpu 13.801 total
After
yarn start 0.30s user 0.06s system 1% cpu 30.274 total