-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
rsbuild.config.ts
248 lines (241 loc) · 6.12 KB
/
rsbuild.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
///<reference path="./src/shared/frontend/imports.d.ts" />
import { defineConfig } from "@rsbuild/core";
import { pluginVue } from "@rsbuild/plugin-vue";
import { pluginCheckSyntax } from "@rsbuild/plugin-check-syntax";
import { pluginAssetsRetry } from "@rsbuild/plugin-assets-retry";
import { InjectManifest } from "@aaroon/workbox-rspack-plugin";
import { pluginSass } from "@rsbuild/plugin-sass";
import { RsdoctorRspackPlugin } from "@rsdoctor/rspack-plugin";
import postcssPresetEnv from "postcss-preset-env";
import { createDescendantRegExp, makeTest } from "@mutsuntsai/rsbuild-utils";
import pkg from "./package.json";
const isProduction = process.env.NODE_ENV === "production";
const useRsdoctor = false;
const inspectBuild = false;
export default defineConfig({
dev: {
progressBar: true,
},
source: {
include: [/@pixi/],
alias: {
"vue-slicksort$": "./node_modules/vue-slicksort/dist/vue-slicksort.esm.js",
"./url.mjs$": "./lib/pixi/url.mjs", // see lib/README.md
},
entry: {
index: "./src/app/main.ts",
donate: "./src/other/donate/main.ts",
},
define: {
// __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: true,
__VUE_I18N_LEGACY_API__: false,
},
tsconfigPath: "./src/app/tsconfig.json",
},
html: {
template: ({ entryName }) => `./build/temp/${entryName}.htm`,
templateParameters: {
VERSION: pkg.version,
APP_VERSION: pkg.app_version,
},
},
server: {
port: 30783,
publicDir: {
name: "src/public",
copyOnBuild: true,
},
historyApiFallback: {
index: "/index.htm",
rewrites: [{ from: /^\/donate/, to: "/donate.htm" }],
},
headers: {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
},
},
performance: !isProduction ? undefined : {
chunkSplit: {
strategy: "custom",
splitChunks: {
cacheGroups: {
vue: {
test: createDescendantRegExp("vue"),
name: "vue",
chunks: "all",
},
index: {
test: makeTest(/src[\\/](app|log)\b/, /idb-keyval/, /probably-china/),
name: "index",
chunks: "all",
},
shared: {
// This contains the modules used both by the main thread and the worker,
// so this must be in a separate file.
test: makeTest(/src[\\/]shared[\\/]/, /tslib/),
name: "shared",
chunks: "async",
priority: -1,
},
pixiUtils: {
test: makeTest(
createDescendantRegExp("@pixi/ticker", "@pixi/math"),
/pixi[\\/]url.mjs/ // see lib/README.md
),
name: "pixi-utils",
chunks: "async",
},
pixiCore: {
test: /@pixi[\\/]core/,
name: "pixi-core",
chunks: "async",
},
pixi: {
test: /@pixi/,
name: "pixi",
chunks: "async",
priority: -1,
},
i18n: {
test: makeTest(createDescendantRegExp("vue-i18n"), /locale\.ts$/, /\.json$/),
name: "vue-i18n",
chunks: "all",
priority: 1,
},
vendor: {
test: createDescendantRegExp("vue-slicksort", "bootstrap"),
name: "vendor",
chunks: "async",
priority: 1,
},
},
},
},
preload: {
type: "all-chunks",
include: [
/\.css$/,
/bps\.\w+\.woff2$/,
/(vue(-\w+)?)\.\w+\.js/,
/(client|shared)\.\w+\.js/,
],
},
},
output: {
cleanDistPath: isProduction,
filename: {
html: "[name].htm", // For historical reason
},
copy: [
{ from: "src/public/manifest.json", to: "." },
// Only precache the two most common resolution; see https://tinyurl.com/7rxv5f97
{ from: "src/public/assets/icon/icon-32.png", to: "assets/icon" },
{ from: "src/public/assets/icon/icon-192.png", to: "assets/icon" },
],
dataUriLimit: 100,
legalComments: inspectBuild ? "inline" : "none",
polyfill: "off",
// sourceMap: { js: "source-map" },
minify: !inspectBuild,
distPath: {
root: "build/dist",
},
},
plugins: [
pluginSass({
sassLoaderOptions: {
sassOptions: {
silenceDeprecations: ["mixed-decls", "color-functions", "import", "global-builtin"],
},
},
}),
pluginVue(),
pluginCheckSyntax({
ecmaVersion: 2019,
}),
pluginAssetsRetry({
addQuery: true,
max: 2,
minify: true,
onFail: ({ url }) => typeof (errMgr) !== "undefined" && errMgr.setResErr(url),
}),
],
tools: {
bundlerChain: (chain, { CHAIN_ID }) => {
chain.module.rule(CHAIN_ID.RULE.JS)
.use("ifdef")
.after(CHAIN_ID.USE.SWC)
.loader("ifdef-loader")
.options({
DEBUG: !isProduction,
});
chain.module.rule(CHAIN_ID.RULE.SASS)
.use("bootstrap-loader")
.after(CHAIN_ID.USE.CSS)
.loader("./lib/bootstrap/loader.mjs");
},
postcss: (_, { addPlugins }) => {
/**
* For the moment, although LightingCSS claims to handle vendor prefixes,
* the functionality seems less complete than postcssPresetEnv.
* For example, `-webkit-text-decoration` is not handled by LightingCSS
* (see https://caniuse.com/text-decoration).
*/
addPlugins(postcssPresetEnv());
},
rspack: (_, { addRules, appendPlugins, isDev }) => {
addRules({
test: /\.md$/,
use: [
"html-minifier-loader",
{
loader: "markdown-loader",
options: {
headerIds: false,
mangle: false,
},
},
],
type: "asset/resource",
generator: {
filename: "log/[name][ext]",
},
});
addRules({
test: /\.json$/,
use: "./lib/locale.mjs",
type: "javascript/auto",
});
if(isDev) return;
if(useRsdoctor) {
appendPlugins(new RsdoctorRspackPlugin({
linter: {
rules: { "ecma-version-check": "off" },
},
supports: {
generateTileGraph: true,
},
}));
}
appendPlugins(new InjectManifest({
swSrc: "./src/other/service/sw.ts",
exclude: [/\.ttf$/],
manifestTransforms: [
/** Only the last log will be included in precache */
manifest => {
let high = 0;
for(const entry of manifest) {
const m = entry.url.match(/(\d+)\.md$/);
if(!m) continue;
const n = Number(m[1]);
if(n > high) high = n;
}
const reg = new RegExp(`(?<!${high})\\.md$`);
manifest = manifest.filter(e => !e.url.match(reg));
return { manifest };
},
],
}));
},
},
});