mirror of
https://github.com/zhigang1992/react.git
synced 2026-01-30 22:48:09 +08:00
chore: add webpack example for tree-shaking
This commit is contained in:
9
examples/tree-shaking-webpack/.babelrc
Normal file
9
examples/tree-shaking-webpack/.babelrc
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"presets": [
|
||||
"@babel/preset-env",
|
||||
"@babel/preset-react"
|
||||
],
|
||||
"plugins": [
|
||||
["import", { "libraryName": "@zeit-ui/react", "libraryDirectory": "esm"}]
|
||||
]
|
||||
}
|
||||
17
examples/tree-shaking-webpack/README.md
Normal file
17
examples/tree-shaking-webpack/README.md
Normal file
@@ -0,0 +1,17 @@
|
||||
## Tree shaking for webpack
|
||||
|
||||
### About
|
||||
|
||||
If you use `webpack` and `babel` to build your Recat project, this example may be useful for you.
|
||||
|
||||
### Previews
|
||||
|
||||
**Before:**
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
**After:**
|
||||
|
||||

|
||||
BIN
examples/tree-shaking-webpack/esm-1.png
Normal file
BIN
examples/tree-shaking-webpack/esm-1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 74 KiB |
BIN
examples/tree-shaking-webpack/esm-2.png
Normal file
BIN
examples/tree-shaking-webpack/esm-2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
28
examples/tree-shaking-webpack/package.json
Normal file
28
examples/tree-shaking-webpack/package.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "tree-shaking-webpack",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"start": "webpack-dev-server --config ./webpack.config.js --mode development",
|
||||
"build": "webpack --config ./webpack.config.js",
|
||||
"analyze": "source-map-explorer 'dist/*.js'"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.9.6",
|
||||
"@babel/preset-env": "^7.9.6",
|
||||
"@babel/preset-react": "^7.9.4",
|
||||
"babel-loader": "^8.1.0",
|
||||
"babel-plugin-import": "^1.13.0",
|
||||
"html-webpack-plugin": "^4.3.0",
|
||||
"source-map-explorer": "^2.4.2",
|
||||
"webpack": "^4.43.0",
|
||||
"webpack-cli": "^3.3.11",
|
||||
"webpack-dev-server": "^3.11.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@zeit-ui/react": "^1.5.0-rc.0",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1"
|
||||
}
|
||||
}
|
||||
9
examples/tree-shaking-webpack/src/index.html
Normal file
9
examples/tree-shaking-webpack/src/index.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Tree Shaking</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
</html>
|
||||
22
examples/tree-shaking-webpack/src/index.js
Normal file
22
examples/tree-shaking-webpack/src/index.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import { ZeitProvider, CssBaseline, Page, Button } from '@zeit-ui/react'
|
||||
|
||||
const App = () => {
|
||||
return (
|
||||
<Page>
|
||||
<p>Hello, world.</p>
|
||||
<Button>Action</Button>
|
||||
</Page>
|
||||
)
|
||||
}
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<ZeitProvider>
|
||||
<CssBaseline />
|
||||
<App />
|
||||
</ZeitProvider>
|
||||
</React.StrictMode>,
|
||||
document.getElementById('app')
|
||||
)
|
||||
40
examples/tree-shaking-webpack/webpack.config.js
Normal file
40
examples/tree-shaking-webpack/webpack.config.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const path = require('path')
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
||||
|
||||
module.exports = {
|
||||
entry: './src/index.js',
|
||||
|
||||
devtool: 'source-map',
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(js|jsx)$/,
|
||||
exclude: /node_modules/,
|
||||
use: ['babel-loader'],
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
resolve: {
|
||||
extensions: ['.js', '.jsx'],
|
||||
},
|
||||
|
||||
output: {
|
||||
path: __dirname + '/dist',
|
||||
publicPath: '/',
|
||||
filename: 'bundle.js',
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({ template: path.join(__dirname, './src/index.html') }),
|
||||
],
|
||||
|
||||
devServer: {
|
||||
host: '127.0.0.1',
|
||||
port: '3000',
|
||||
contentBase: './dist',
|
||||
hot: true,
|
||||
open: true,
|
||||
}
|
||||
};
|
||||
5557
examples/tree-shaking-webpack/yarn.lock
Normal file
5557
examples/tree-shaking-webpack/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user