-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
100 lines (98 loc) · 2.41 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
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const port = process.env.PORT || 3000;
module.exports = {
mode: "development",
entry: {
app: path.join(__dirname, "src", "index.tsx"),
},
output: {
filename: "[name].[contenthash].bundle.js",
// filename: "index.bundle.js",
path: path.resolve(__dirname, "dist"),
publicPath: "/",
clean: true,
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
devServer: {
host: "localhost",
port: port,
// open: true,
historyApiFallback: true,
},
devtool: "source-map",
optimization: {
splitChunks: {
chunks: "all",
minSize: 80000,
maxSize: 240000,
cacheGroups: {
styles: {
name: "styles",
test: /\.css$/,
chunks: "all",
enforce: true,
},
defaultVendors: {
enforce: true,
filename: "v.[name].[contenthash].bundle.js",
},
},
},
minimize: true,
minimizer: [
// default is actually smaller in resultin bundle sizes
// than swc and doesnt wipe all the license comments
// this lil rust compiler is only a bit faster :(
new TerserPlugin({
// minify: TerserPlugin.swcMinify,
// terserOptions: {},
}),
],
},
// externals: { react: "react", ReactDOM: "react-dom" },
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
{
test: /\.(css|scss)$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.(jpg|jpeg|png|gif|mp3|svg)$/,
use: ["file-loader"],
},
{
test: /\.worker\.tsx$/,
exclude: /node_modules/,
use: [
{
loader: "worker-loader",
options: {
filename: "[name].[contenthash].worker.js",
chunkFilename: "[id].[contenthash].worker.js",
},
},
{
loader: "babel-loader",
},
],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, "public", "index.html"),
favicon: path.join(__dirname, "public", "favicon.ico"),
}),
new CompressionWebpackPlugin(),
],
};