Skip to content

Commit d87933e

Browse files
committed
feat: expanded webpack optimization
1 parent 000e9b0 commit d87933e

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
"csv-loader": "^3.0.2",
3232
"file-loader": "^6.0.0",
3333
"html-webpack-plugin": "^4.0.3",
34+
"optimize-css-assets-webpack-plugin": "^5.0.3",
3435
"papaparse": "^5.1.1",
3536
"style-loader": "^1.1.3",
37+
"terser-webpack-plugin": "^2.3.5",
3638
"webpack": "^4.42.1",
3739
"webpack-cli": "^3.3.11",
3840
"xml-loader": "^1.2.1"

webpack.config.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@ const path = require("path");
22
const HTMLWebpackPlugin = require("html-webpack-plugin");
33
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
44
const CopyWebpackPlugin = require('copy-webpack-plugin');
5+
const OptimizeCSSAssetPlugin = require("optimize-css-assets-webpack-plugin");
6+
const TerserWebpackPlugin = require("terser-webpack-plugin");
7+
8+
const isDev = process.env.NODE_ENV === "development";
9+
const isProd = !isDev;
10+
11+
const optimization = () => {
12+
const config = {
13+
splitChunks: {
14+
chunks: "all"
15+
}
16+
}
17+
18+
if (isProd) {
19+
config.minimizer = [
20+
new OptimizeCSSAssetPlugin(),
21+
new TerserWebpackPlugin()
22+
]
23+
}
24+
}
525

626
module.exports = {
727
context: path.resolve(__dirname, "src"),
@@ -22,14 +42,13 @@ module.exports = {
2242
"@": path.resolve(__dirname, "src")
2343
}
2444
},
25-
optimization: {
26-
splitChunks: {
27-
chunks: "all"
28-
}
29-
},
45+
optimization: optimization(),
3046
plugins: [
3147
new HTMLWebpackPlugin({
32-
template: "./index.html"
48+
template: "./index.html",
49+
minify: {
50+
collapseWhitespace: isProd
51+
}
3352
}),
3453
new CleanWebpackPlugin(),
3554
new CopyWebpackPlugin([

0 commit comments

Comments
 (0)