-
Notifications
You must be signed in to change notification settings - Fork 19
/
webpack.config.js
97 lines (92 loc) · 2.22 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
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const BrotliPlugin = require("brotli-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const path = require("path");
const IS_DEV = process.env.NODE_ENV === "development";
const IS_PROD = !IS_DEV;
module.exports = {
entry: {
app: ["./src/index.tsx"]
},
context: path.resolve(__dirname),
mode: IS_DEV ? "development" : "production",
target: "web",
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].[hash:7].js",
publicPath: "/"
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
use: [
{
loader: "file-loader"
}
]
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"]
}
]
},
plugins: [
new webpack.EnvironmentPlugin(["NODE_ENV", "NET"]),
new HtmlWebpackPlugin({
filename: "index.html",
template: `${__dirname}/static/index.html`
}),
...(IS_PROD
? [
new CompressionPlugin({ test: /\.(js|css|html|svg)$/ }),
new BrotliPlugin({ test: /\.(js|css|html|svg)$/ }),
new CopyWebpackPlugin([{ from: "static/images", to: "static/images" }])
]
: [])
],
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /\/node_modules\//,
name: "vendor",
chunks: "all"
}
}
}
},
// Using cheap-eval-source-map for build times
// switch to inline-source-map if detailed debugging needed
devtool: IS_PROD ? false : "cheap-eval-source-map",
devServer: {
compress: true,
disableHostCheck: true,
historyApiFallback: true,
hot: true,
inline: true,
port: 3010,
stats: {
colors: true,
progress: true
}
},
resolve: {
extensions: [".js", ".ts", ".tsx"],
modules: ["node_modules", path.resolve(__dirname, "src")],
alias: {
"react-dom": "@hot-loader/react-dom"
}
},
bail: true
};