Skip to content

Commit 0dc1f02

Browse files
committed
Added HtmlWebpackPlugin and BundleAnalyzerPlugin
1 parent 65b36c9 commit 0dc1f02

File tree

5 files changed

+370
-13
lines changed

5 files changed

+370
-13
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# production
1010
/build
1111

12+
# analyzer
13+
/stats
14+
1215
# misc
1316
.DS_Store
1417
.env.local

index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>My React Configuration Setup</title>
4+
<title>JavaScript Patterns</title>
55
</head>
66
<body>
7-
<div id="root"></div>
8-
<script src="./dist/bundle.js"></script>
7+
<div id="root" />
98
</body>
109
</html>

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"scripts": {
1010
"start": "webpack-dev-server --mode development",
1111
"format": "prettier --write \"src/**/*.js\"",
12+
"stats": "webpack-bundle-analyzer stats/stats.json",
1213
"build": "webpack --mode production"
1314
},
1415
"devDependencies": {
@@ -21,8 +22,10 @@
2122
"eslint-config-react": "^1.1.7",
2223
"eslint-loader": "^2.1.1",
2324
"eslint-plugin-react": "^7.12.4",
25+
"html-webpack-plugin": "^3.2.0",
2426
"prettier": "1.16.2",
2527
"webpack": "^4.29.0",
28+
"webpack-bundle-analyzer": "^3.0.3",
2629
"webpack-cli": "^3.2.1",
2730
"webpack-dev-server": "^3.1.14"
2831
}

webpack.config.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
const path = require('path');
2+
const HtmlWebpackPlugin = require('html-webpack-plugin');
3+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
24

35
module.exports = {
46
devtool: 'inline-source-map',
57
entry: './src/index.js',
68
output: {
7-
path: path.join(__dirname, '/dist'),
9+
path: path.join(__dirname, '/build'),
810
publicPath: '/',
911
filename: 'bundle.js'
1012
},
13+
optimization: {
14+
splitChunks: {
15+
chunks: 'all'
16+
}
17+
},
1118
devServer: {
12-
contentBase: './',
13-
publicPath: '/dist/'
19+
contentBase: './build'
1420
},
1521
module: {
1622
rules: [
@@ -20,5 +26,17 @@ module.exports = {
2026
use: ['babel-loader', 'eslint-loader']
2127
}
2228
]
23-
}
29+
},
30+
plugins: [
31+
new HtmlWebpackPlugin({
32+
template: path.resolve('./index.html')
33+
}),
34+
new BundleAnalyzerPlugin({
35+
analyzerMode: 'disabled',
36+
generateStatsFile: true,
37+
statsOptions: { source: false },
38+
statsFilename: path.join(__dirname, 'stats/stats.json')
39+
})
40+
],
41+
performance: { hints: false }
2442
};

0 commit comments

Comments
 (0)