-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
90 lines (89 loc) · 2.4 KB
/
webpack.config.js
File metadata and controls
90 lines (89 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ScriptExtHtmlPlugin = require("script-ext-html-webpack-plugin");
const JsConfigWebpackPlugin = require("js-config-webpack-plugin");
const ImageConfigWebpackPlugin = require("image-config-webpack-plugin");
const ScssConfigWebpackPlugin = require("scss-config-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const outputDir = path.join(__dirname, "dist/");
module.exports = {
entry: {
app: "./src/Index.bs.js"
},
mode: "production",
output: {
path: outputDir,
chunkFilename: "static/[name].[chunkhash:8].js",
filename: "static/[name].[chunkhash:8].js",
publicPath: "/"
},
plugins: [
new CopyPlugin([
{
from: "public",
to: `${outputDir}`,
ignore: ["index.html"]
}
]),
new CleanWebpackPlugin(),
new JsConfigWebpackPlugin(),
new ScssConfigWebpackPlugin(),
new ImageConfigWebpackPlugin(),
new HtmlWebpackPlugin({
minify: {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true,
useShortDoctype: true,
minifyCSS: true,
minifyJS: true,
caseSensitive: true
},
hash: true,
inject: true,
template: "./public/index.html"
}),
new ScriptExtHtmlPlugin({
defaultAttribute: "defer",
module: ["app"]
})
],
optimization: {
nodeEnv: "production",
concatenateModules: true,
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true, // Must be set to true if using source-maps in production
terserOptions: {
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
}
})
],
splitChunks: {
chunks: "all",
cacheGroups: {
commons: {
test: /node_modules/,
chunks: "initial",
name: "common",
priority: 10,
enforce: true
}
}
}
},
devServer: {
compress: true,
contentBase: outputDir,
port: process.env.PORT || 3000,
historyApiFallback: true
}
};