-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
119 lines (116 loc) · 2.85 KB
/
webpack.config.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const path = require("path");
const { execSync } = require("child_process");
const webpack = require("webpack");
const DefinePlugin = require("webpack/lib/DefinePlugin");
const CompressionPlugin = require("compression-webpack-plugin");
const HtmlPlugin = require("html-webpack-plugin");
const config = {
entry: {
old: "./src/old.js",
new: "./src/new.tsx",
perf: "./src/perf.ts",
},
output: {
filename: "[contenthash]/[name].js",
assetModuleFilename: "[hash:20]/[name][ext]",
path: path.resolve(__dirname, "dist"),
},
resolve: {
extensions: [".js", ".ts", ".jsx", ".tsx"],
},
module: {
rules: [
{
test: /[.]sass$/,
exclude: /[/]node_modules[/]/,
use: [
"style-loader",
"css-loader",
{
loader: "sass-loader",
options: {
implementation: require("sass"),
},
},
],
},
{
test: /[.]worker[.](js|ts)x?$/,
exclude: /[/]node_modules[/]/,
use: [
{
loader: "worker-loader",
options: {
inline: "no-fallback",
chunkFilename: "[hash:20]/[name].js",
},
},
],
},
{
test: /[.](js|ts)x?$/,
exclude: /[/]node_modules[/]/,
loader: "babel-loader",
},
{
test: /[.](woff2|woff|ttf|otf)$/,
exclude: /[/]node_modules[/]/,
type: "asset/resource",
},
{
test: /[.]bin$/,
exclude: /[/]node_modules[/]/,
type: "asset/resource",
},
],
},
plugins: [
new DefinePlugin({
__COMMIT_HASH__: JSON.stringify(
`${execSync("git rev-parse HEAD")}`.trim(),
),
}),
new HtmlPlugin({
filename: "old.html",
template: "src/old.html",
chunks: ["old"],
}),
new HtmlPlugin({
filename: "index.html",
template: "src/new.html",
chunks: ["new"],
}),
new HtmlPlugin({
filename: "perf.html",
template: "src/perf.html",
chunks: ["perf"],
}),
],
ignoreWarnings: [
// TEMP: old versions of frontend dependencies trigger deprecation warnings in sass
// TODO: remove once frontend dependencies are upgraded
{ module: /node_modules/ },
],
};
module.exports = (env, argv) => {
switch (argv.mode) {
case "production":
config.devtool = "source-map";
config.plugins.push(
new CompressionPlugin({
filename: "[file].br[query]",
algorithm: "brotliCompress",
test: /[.](js|eot|svg|ttf|woff|woff2|otf|bin)$/,
}),
);
break;
case "development":
config.devtool = "eval-cheap-module-source-map";
break;
default:
// breaks webpack-dev-server
// config.plugins.push(new webpack.debug.ProfilingPlugin());
break;
}
return config;
};