-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrsbuild.config.ts
161 lines (156 loc) · 3.61 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
import { glob } from "glob";
import { defineConfig } from "@rsbuild/core";
import { pluginReact } from "@rsbuild/plugin-react";
import { pluginCheckSyntax } from "@rsbuild/plugin-check-syntax";
import { GenerateSW } from "workbox-webpack-plugin";
import { PurgeCSSPlugin } from "purgecss-webpack-plugin";
import { pluginAssetsRetry } from "@rsbuild/plugin-assets-retry";
import { pluginSass } from "@rsbuild/plugin-sass";
import { pluginHtmlMinifierTerser } from "rsbuild-plugin-html-minifier-terser";
import { createDescendantRegExp, makeTest } from "@mutsuntsai/rsbuild-utils";
import * as pkg from "./package.json";
const isProduction = process.env.NODE_ENV === "production";
export default defineConfig({
dev: {
progressBar: true,
// See https://github.com/web-infra-dev/rspack/issues/8503
lazyCompilation: { entries: false, imports: true },
},
source: {
include: [
// add matcher for packages that needs to be transpiled
/i18next/,
/chart\.js/,
],
define: {
__VERSION__: `"${pkg.version}"`,
},
entry: {
index: "./src/app/index.tsx",
},
tsconfigPath: "./src/app/tsconfig.json",
},
html: {
template: "./src/public/index.html",
},
server: {
port: 31213,
base: "/reference-finder",
publicDir: {
name: "src/public",
copyOnBuild: true,
},
},
performance: {
chunkSplit: {
strategy: "custom",
splitChunks: {
cacheGroups: {
rabbit: {
test: /rabbit-ear/,
name: "rabbit-ear",
chunks: "initial",
},
react: {
test: /react/,
name: "react",
chunks: "initial",
},
vendor: {
test: /node_modules/,
name: "vendor",
chunks: "initial",
priority: -1,
},
ui: {
test: makeTest(/src[\\/]app[\\/]components/, /node_modules/),
name: "ui",
chunks: "async",
priority: -1,
},
chart: {
test: createDescendantRegExp("chart.js", "chartjs-plugin-datalabels", "react-chartjs-2"),
name: "chart",
chunks: "async",
},
},
},
},
preload: {
type: "all-chunks",
include: [/fa-.+\.woff2$/],
},
},
output: {
cleanDistPath: isProduction,
copy: [
// Uncomment these two lines for WASM debugging
// { from: "ref.wasm.map", context: "./src/lib/", to: "static/wasm/" },
// { from: "core/**/*", context: "./src/", to: "static" },
],
dataUriLimit: 100,
legalComments: "none",
polyfill: "off",
minify: {
jsOptions: {
minimizerOptions: {
format: {
asciiOnly: false, // do not escape unicode in strings
},
},
},
},
distPath: {
root: "docs",
},
},
plugins: [
pluginSass({
sassLoaderOptions: {
sassOptions: {
silenceDeprecations: ["mixed-decls", "color-functions", "import", "global-builtin"],
},
},
}),
pluginReact(),
pluginCheckSyntax({
ecmaVersion: 2018,
}),
pluginAssetsRetry({
addQuery: true,
test: url => !url.includes("gtag"),
}),
pluginHtmlMinifierTerser({
removeComments: true,
}),
],
tools: {
rspack: (_, { appendPlugins, isDev }) => {
if(isDev) return;
// Using postcss-purgecss is an alternative,
// but that will result in chunks being processed separately.
appendPlugins(new PurgeCSSPlugin({
paths: glob.sync(["./src/app/**/*.tsx", "./src/public/index.html"]),
variables: true,
safelist: {
standard: [
/backdrop/,
/bs-theme/,
/tooltip/,
/modal-static/,
],
greedy: [
/tooltip-arrow/,
/creasePattern|boundary/,
/(point|line|arc|label|target)-/,
],
},
blocklist: [],
}));
appendPlugins(new GenerateSW({
clientsClaim: true,
skipWaiting: true,
}));
},
},
});