-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
105 lines (101 loc) · 2.88 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
/* eslint-env node */
const path = require("path");
const zlib = require("zlib");
const TerserPlugin = require("terser-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const getPlugins = (isProduction) => {
const plugins = [
new HtmlWebpackPlugin({
template: "./src/index.html",
favicon: path.join(__dirname, "./src/assets/images/favicon.png"),
}),
];
if (isProduction) {
plugins.push(
new CompressionPlugin({
filename: "[path][base].gz",
algorithm: "gzip",
test: /\.(js|css|ts|tsx|html)$/,
threshold: 10240,
minRatio: 0.8,
}),
new CompressionPlugin({
filename: "[path][base].br",
algorithm: "brotliCompress",
test: /\.(js|css|ts|tsx|html|svg)$/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false,
})
);
}
return plugins;
};
module.exports = (env) => {
const nodeEnv = env.WEBPACK_SERVE ? "development" : "production";
const isProduction = nodeEnv === "production";
const plugins = getPlugins(isProduction);
return {
mode: nodeEnv,
entry: "./src/index.tsx",
output: {
path: path.join(__dirname, "./build"),
filename: "[name].[contenthash].bundle.js",
publicPath: "/",
clean: true,
},
resolve: {
extensions: [".ts", ".tsx", ".js", "jsx", ".json"],
alias: {
api: path.resolve(__dirname, "src/api/"),
assets: path.resolve(__dirname, "src/assets/"),
components: path.resolve(__dirname, "src/components/"),
containers: path.resolve(__dirname, "src/containers/"),
hooks: path.resolve(__dirname, "src/hooks/"),
models: path.resolve(__dirname, "src/models/"),
pages: path.resolve(__dirname, "src/pages/"),
src: path.resolve(__dirname, "src/"),
},
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: { loader: "swc-loader" },
},
{ test: /\.css$/, use: ["style-loader", "css-loader"] },
{ test: /\.(png|jpg|jpeg|woff2)$/, use: ["file-loader"] },
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ["@svgr/webpack"],
},
],
},
devServer: {
historyApiFallback: true,
open: !isProduction,
port: 3000,
hot: true,
},
plugins,
optimization: {
minimize: isProduction,
minimizer: isProduction
? [new TerserPlugin(), new CssMinimizerPlugin()]
: [],
splitChunks: {
chunks: "all",
},
},
};
};
process.on("SIGINT", () => process.exit(0));