-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
126 lines (112 loc) · 2.79 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const CopyPlugin = require("copy-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { parse, resolve } = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const { ProgressPlugin } = require("webpack");
const context = resolve(process.cwd(), "src/www");
const regExp = {
images: /\.(a?png|gif|jpe?g|svg|webp)$/i,
fonts: /\.(otf|ttf|woff2?)$/i,
multimedia: /\.(mp3|webm|mp4)$/i,
};
const isDevelopment = process.env.NODE_ENV === "development";
const isProduction = !isDevelopment;
module.exports = {
mode: isDevelopment ? "development" : "production",
context,
devtool: isDevelopment ? "eval" : false,
watch: isDevelopment,
watchOptions: {
aggregateTimeout: 500,
},
entry: {
app: ["./ts/index.ts", "./css/app.css"],
overlay: ["./ts/overlay.ts"],
"chat-overlay": ["./ts/chat-overlay.ts", "./css/chat-overlay.css"],
},
output: {
path: resolve(process.cwd(), "dist/www"),
filename: "assets/js/[name].js",
publicPath: "/",
assetModuleFilename: (pathData) => {
const { filename } = pathData;
if (!filename) {
return "[name][ext]";
}
const { ext } = parse(filename);
let contentType;
for (const type of Object.keys(regExp)) {
if (regExp[type].test(filename)) {
contentType = type;
}
}
if (!contentType) {
contentType = "miscellaneous";
console.log(`Unknown extension ${ext}, falling back to ${contentType}`);
}
return `assets/${contentType}/[name][ext]`;
},
},
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
importLoaders: true,
},
},
"postcss-loader",
],
},
{
test: regExp.images,
type: "asset/resource",
},
{
test: regExp.multimedia,
type: "asset/resource",
},
{
test: regExp.fonts,
type: "asset/resource",
},
],
},
resolve: {
extensions: [".ts"],
},
plugins: [
new ProgressPlugin(),
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: "*.html",
to: ".",
},
],
}),
new MiniCssExtractPlugin({
filename: "assets/css/[name].css",
chunkFilename: "assets/css/[id].css",
}),
],
optimization: {
minimize: isProduction,
minimizer: ["...", new CssMinimizerPlugin()],
splitChunks: {
minSize: 10e3,
maxSize: 250e3,
},
},
};