Skip to content

Commit 44805db

Browse files
authored
perf(core): minify large third-party chunks (#8160)
1 parent a5818c9 commit 44805db

3 files changed

Lines changed: 44 additions & 11 deletions

File tree

packages/core/rslib.config.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export const define = {
1212
'process.env.WS_NO_UTF_8_VALIDATE': true,
1313
};
1414

15+
const fullyMinifiedChunks =
16+
/^(?:chokidar|connect-next|http-proxy-middleware|launch-editor-middleware|manifest-plugin|memfs|open|tinyglobby|ws)\.js$/;
17+
1518
const regexpMap: Record<string, RegExp> = {};
1619

1720
for (const item of prebundleConfig.dependencies) {
@@ -204,7 +207,18 @@ export default defineConfig({
204207
},
205208
},
206209
output: {
207-
minify: nodeMinifyConfig,
210+
minify: {
211+
jsOptions: [
212+
{
213+
// Fully minify large chunks composed primarily of third-party code.
214+
include: fullyMinifiedChunks,
215+
},
216+
{
217+
...nodeMinifyConfig.jsOptions,
218+
exclude: fullyMinifiedChunks,
219+
},
220+
],
221+
},
208222
filename: {
209223
js: ({ chunk }) => {
210224
// Use `.mjs` for Rspack loaders

pnpm-lock.yaml

Lines changed: 27 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/config/rslib.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { pluginAreTheTypesWrong } from 'rsbuild-plugin-arethetypeswrong';
33

44
export const commonExternals: Array<string | RegExp> = ['webpack', /[\\/]compiled[\\/]/];
55

6-
export const nodeMinifyConfig: Rsbuild.Minify = {
6+
export const nodeMinifyConfig = {
77
js: true,
88
css: false,
99
jsOptions: {
@@ -16,7 +16,7 @@ export const nodeMinifyConfig: Rsbuild.Minify = {
1616
},
1717
},
1818
},
19-
};
19+
} satisfies Rsbuild.Minify;
2020

2121
export const esmConfig: LibConfig = {
2222
syntax: 'es2023',

0 commit comments

Comments
 (0)