-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
98 lines (92 loc) · 2.85 KB
/
webpack.config.ts
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
import path from "path";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import CopyPlugin from "copy-webpack-plugin";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import ExtractCssChunks from "extract-css-chunks-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import OptimizeCSSAssetsPlugin from "optimize-css-assets-webpack-plugin";
import TerserPlugin from "terser-webpack-plugin";
import webpack from "webpack";
import Optimization = webpack.Options.Optimization;
const WEBPACK_MODES = {
development: "development",
production: "production",
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
module.exports = (env: any, argv: any): any => {
const mode = argv.mode || WEBPACK_MODES.development;
const isProd = mode === WEBPACK_MODES.production;
const optimization: Optimization = {
splitChunks: {
chunks: "all",
},
};
if (isProd) {
optimization.minimize = true;
optimization.minimizer = [
new TerserPlugin({}),
new OptimizeCSSAssetsPlugin({}),
];
}
return {
entry: {
app: "./src/index.tsx",
},
output: {
path: path.join(__dirname, "dist"),
filename: "[name].bundle.js",
publicPath: "/",
},
module: {
rules: [
{
test: /\.([tj])sx?$/,
exclude: /node_modules/,
use: { loader: "awesome-typescript-loader" },
},
{
test: /\.(css|scss|less)$/,
use: [
{
loader: ExtractCssChunks.loader,
options: {
hmr: !isProd,
reloadAll: true,
},
},
"css-loader",
"less-loader",
],
},
],
},
resolve: {
modules: ["node_modules"],
extensions: [".tsx", ".ts", ".jsx", ".js"],
},
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: "public",
to: ".",
},
],
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "src", "index.html"),
}),
new ExtractCssChunks(),
],
devtool: "source-map",
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true,
historyApiFallback: true,
overlay: true,
},
optimization,
};
};