-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
97 lines (95 loc) · 2.43 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 webpack = require("webpack");
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
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].[fullhash:7].js",
publicPath: "/",
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
type: "asset",
},
{
resourceQuery: /inline/,
type: "asset/inline",
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
],
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new webpack.EnvironmentPlugin(["NODE_ENV"]),
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({
patterns: [{ from: "static/images", to: "static/images" }],
}),
]
: []),
],
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /\/node_modules\//,
name: "vendor",
chunks: "all",
},
},
},
},
devtool: IS_PROD ? false : "eval-cheap-module-source-map", // https://webpack.js.org/configuration/devtool
devServer: {
compress: true,
historyApiFallback: true,
hot: true,
port: 3000,
},
resolve: {
extensions: [".js", ".ts", ".tsx"],
modules: ["node_modules", path.resolve(__dirname, "src")],
alias: {
react: path.resolve("./node_modules/react"),
},
fallback: {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
timers: require.resolve("timers-browserify"),
buffer: require.resolve("buffer"),
},
},
bail: true,
};