-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add section to describe how to reduce build size (#748)
* chore(examples): update tree-shaking for webpack project * chore(examples): simplify the config of tree-shaking for webpack 5 * docs: add section to describe how to reduce build size
- Loading branch information
Showing
31 changed files
with
258 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,3 @@ | ||
## Tree shaking for create react app | ||
|
||
This is example of `tree-shaking` for [create-react-app](https://github.com/facebook/create-react-app). | ||
By default, we do not `eject` configs from `create-react-app`, in this example, | ||
we use [react-app-rewired](https://github.com/timarney/react-app-rewired) to change the default configs. | ||
|
||
### About | ||
|
||
- Add `config-overrides.js` to your root folder. | ||
- Add deps: `yarn add babel-plugin-import customize-cra react-app-rewired -D` | ||
- Replace your default scripts(`react-scripts`) with `react-app-rewired`. | ||
|
||
### Previews | ||
|
||
**Before:** | ||
|
||
![before](public/esm-1.png) | ||
|
||
<br /> | ||
|
||
**After:** | ||
|
||
![after](public/esm-2.png) | ||
Full tree-shaking is automatically available without any configuration when using `react-scripts 5.0.0` or higher. (`webpack > 5.0`) |
10 changes: 10 additions & 0 deletions
10
examples/tree-shaking-create-react-app/build/asset-manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"files": { | ||
"main.js": "/static/js/main.c0df7028.js", | ||
"index.html": "/index.html", | ||
"main.c0df7028.js.map": "/static/js/main.c0df7028.js.map" | ||
}, | ||
"entrypoints": [ | ||
"static/js/main.c0df7028.js" | ||
] | ||
} |
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Tree Shaking</title><script defer="defer" src="/static/js/main.c0df7028.js"></script></head><body><div id="app"></div></body></html> |
3 changes: 3 additions & 0 deletions
3
examples/tree-shaking-create-react-app/build/static/js/main.c0df7028.js
Large diffs are not rendered by default.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
examples/tree-shaking-create-react-app/build/static/js/main.c0df7028.js.LICENSE.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
object-assign | ||
(c) Sindre Sorhus | ||
@license MIT | ||
*/ | ||
|
||
/** @license React v0.20.2 | ||
* scheduler.production.min.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
/** @license React v17.0.2 | ||
* react-dom.production.min.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
/** @license React v17.0.2 | ||
* react-jsx-runtime.production.min.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
/** @license React v17.0.2 | ||
* react.production.min.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
const withTM = require('next-transpile-modules')(['@geist-ui/core']) | ||
const withBundleAnalyzer = require('@next/bundle-analyzer')({ | ||
enabled: process.env.ANALYZE === 'true', | ||
}) | ||
|
||
module.exports = withTM(withBundleAnalyzer({})) | ||
module.exports = withBundleAnalyzer({ | ||
eslint: { | ||
ignoreDuringBuilds: true, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
{ | ||
"name": "tree-shaking-nextjs", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"analyze": "ANALYZE=true yarn build" | ||
}, | ||
"dependencies": { | ||
"@geist-ui/core": "latest", | ||
"next": "9.4.2", | ||
"react": "16.13.1", | ||
"react-dom": "16.13.1" | ||
"@geist-ui/core": "^2.3.3", | ||
"next": "^12.1.0", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2" | ||
}, | ||
"devDependencies": { | ||
"@next/bundle-analyzer": "^9.4.4", | ||
"babel-plugin-import": "^1.13.0", | ||
"next-transpile-modules": "^3.3.0" | ||
"@next/bundle-analyzer": "^9.4.4" | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env", "@babel/preset-react"], | ||
"plugins": [["import", { "libraryName": "@geist-ui/core", "libraryDirectory": "esm" }]] | ||
"presets": ["@babel/preset-env", "@babel/preset-react"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.