-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
153 lines (151 loc) · 5.49 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import path from "path";
import HtmlWebpackPlugin from "html-webpack-plugin";
import webpack from "webpack";
import { VueLoaderPlugin } from "vue-loader";
const svgToMiniDataURI = require("mini-svg-data-uri");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const HtmlWebpackInlineSVGPlugin = require("html-webpack-inline-svg-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
function getConfig(_: any, options: any) {
const mode = options.mode;
const finalCSSLoader =
mode == "development" ? "style-loader" : MiniCssExtractPlugin.loader;
const config: webpack.Configuration = {
mode,
entry: {
room: "./front/index.ts",
upload: "./front/upload.ts",
stats: "./front/stats.ts",
splash: "./front/splash.ts",
},
output: {
filename:
mode == "production" ? "[name].[contenthash].js" : "[name].js",
path: path.resolve(__dirname, "dist"),
publicPath: "/",
},
resolve: {
extensions: [".ts", ".js", ".json", ".vue"],
fallback: { util: require.resolve("util/") },
},
devtool: mode == "development" ? "eval-cheap-module-source-map" : false,
module: {
rules: [
{
test: /\.vue$/i,
loader: "vue-loader",
options: { hotReload: false },
},
{
test: /\.css$/i,
use: [finalCSSLoader, "css-loader"],
},
{
test: /\.scss$/i,
use: [finalCSSLoader, "css-loader", "sass-loader"],
},
{
test: /\.inline\.svg$/i,
type: "asset/inline",
generator: {
dataUrl: (content: string) => {
content = content.toString();
return svgToMiniDataURI(content);
},
},
},
{
test: /\.vue\.svg$/i,
use: [
"vue-loader",
{
loader: "vue-svg-loader",
options: {
svgo: {
plugins: [
{
prefixIds: {
prefixClassNames: false,
},
},
],
},
},
},
],
},
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/,
options: {
appendTsSuffixTo: [/\.vue$/],
configFile: "tsconfig.webpack.json",
compiler: "ttypescript",
ignoreDiagnostics: [7006, 2363, 2365], // deal with weird problem with vue-loader
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
inject: true,
template: "./front/html/room.html",
chunks: ["room"],
filename: "room.html",
}),
new HtmlWebpackPlugin({
inject: true,
template: "./front/html/index.html",
chunks: ["splash"],
filename: "index.html",
}),
new HtmlWebpackPlugin({
inject: true,
template: "./front/html/upload.html",
chunks: ["upload"],
filename: "upload/index.html",
}),
new HtmlWebpackPlugin({
inject: true,
template: "./front/html/stats.html",
chunks: ["stats"],
filename: "stats/index.html",
}),
new webpack.DefinePlugin({
__VUE_PROD_DEVTOOLS__: false,
__VUE_OPTIONS_API__: false,
}),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({ filename: "[name].[contenthash].css" }),
new webpack.WatchIgnorePlugin({
paths: [path.resolve(__dirname, "back")],
}),
new HtmlWebpackInlineSVGPlugin(),
new CleanWebpackPlugin(),
],
optimization: {
minimizer: [new CssMinimizerPlugin(), "..."],
splitChunks: {
cacheGroups: {
indexCSS: {
type: "css/mini-extract",
name: "index_css",
chunks: (chunk) => chunk.name == "index",
enforce: true,
},
uploadCSS: {
type: "css/mini-extract",
name: "upload_css",
chunks: (chunk) => chunk.name == "upload",
enforce: true,
},
},
},
realContentHash: false,
},
};
return config;
}
export default getConfig;