This repository was archived by the owner on Sep 7, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathwebpack.config.js
More file actions
70 lines (69 loc) · 2.18 KB
/
Copy pathwebpack.config.js
File metadata and controls
70 lines (69 loc) · 2.18 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
var path = require("path");
var webpack = require("webpack");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var TerserPlugin = require("terser-webpack-plugin");
module.exports = ({ googleAnalytics, longTermCaching } = {}, { mode } = {}) => ({
entry: {
web: "./app/entry.js"
},
cache: {
type: "filesystem",
buildDependencies: {
config: [__filename]
}
},
// Ported from the Grunt "webpack-dev-server:development" task, which merged
// `devtool: "eval"` into the config for dev builds only.
devtool: mode === "development" ? "eval" : false,
devServer: {
port: 8080,
// `contentBase: "dist"` is deliberately not carried over. It existed to
// serve the index.html that the Grunt "copy" task wrote into dist/; that
// file is now generated by HtmlWebpackPlugin and served from memory, so
// pointing the dev server at dist/ would only let a stale production
// build shadow it. `keepAlive` was a Grunt task-runner concern.
static: false
},
// Replaces the Grunt production task's `webpack.optimize.UglifyJsPlugin()`.
// Only applied when `optimization.minimize` is on, which `--mode production`
// enables and `--mode development` does not.
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
// Keep third-party license banners out of the bundles but still
// shipped, in a sidecar <chunk>.js.LICENSE.txt file.
extractComments: true,
terserOptions: {
// webpack's built-in default minimizer uses two compress
// passes; keep parity so making this explicit does not
// regress output size.
compress: { passes: 2 },
format: { comments: false }
}
})
]
},
output: {
publicPath: "",
filename: "[name].js",
chunkFilename: longTermCaching ? "[contenthash].js" : undefined
},
module: {
rules: [
{ test: /\.pug$/, use: "pug-loader" },
{ test: /\.css$/, use: ["style-loader", "css-loader"] },
{ test: /\.png$/, type: "asset" }
]
},
plugins: [
new HtmlWebpackPlugin({
template: "./app/index.html"
}),
googleAnalytics &&
new webpack.DefinePlugin({
GA_TRACKING_CODE: JSON.stringify("UA-46921629-1"),
GA_TRACKING_CONFIG: JSON.stringify("webpack.github.io")
})
].filter(Boolean)
});