Skip to content

Commit ea5491b

Browse files
feat: enable lazyCompilation.imports by default (#5824)
1 parent cc6e7c6 commit ea5491b

File tree

7 files changed

+80
-14
lines changed

7 files changed

+80
-14
lines changed

e2e/cases/nonce/dynamic-chunk/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import { build, dev } from '@e2e/helper';
22
import { expect, test } from '@playwright/test';
33

4+
declare global {
5+
interface Window {
6+
dynamicChunkNonce?: string;
7+
}
8+
}
9+
410
test('should apply nonce to dynamic chunks in dev build', async ({ page }) => {
511
const rsbuild = await dev({
612
cwd: __dirname,
713
page,
814
});
915

16+
await page.waitForFunction(
17+
() => window.dynamicChunkNonce !== undefined,
18+
undefined,
19+
{
20+
timeout: 2000,
21+
},
22+
);
23+
1024
expect(await page.evaluate('window.dynamicChunkNonce')).toEqual(
1125
'CSP_NONCE_PLACEHOLDER',
1226
);

packages/compat/webpack/tests/__snapshots__/default.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
2424
},
2525
"experiments": {
2626
"asyncWebAssembly": true,
27+
"lazyCompilation": {
28+
"entries": false,
29+
"imports": true,
30+
},
2731
},
2832
"infrastructureLogging": {
2933
"level": "error",
@@ -482,6 +486,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ
482486
},
483487
"experiments": {
484488
"asyncWebAssembly": true,
489+
"lazyCompilation": {
490+
"entries": false,
491+
"imports": true,
492+
},
485493
},
486494
"infrastructureLogging": {
487495
"level": "error",

packages/core/src/client/hmr.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ function formatURL(fallback?: boolean) {
2929
}
3030

3131
// Remember some state related to hot module replacement.
32-
let isFirstCompilation = true;
3332
let lastCompilationHash: string | undefined;
3433
let hasCompileErrors = false;
3534

@@ -55,22 +54,15 @@ export const registerOverlay = (
5554
function handleSuccess() {
5655
clearOutdatedErrors();
5756

58-
const isHotUpdate = !isFirstCompilation;
59-
isFirstCompilation = false;
6057
hasCompileErrors = false;
6158

62-
// Attempt to apply hot updates or reload.
63-
if (isHotUpdate) {
64-
tryApplyUpdates();
65-
}
59+
tryApplyUpdates();
6660
}
6761

6862
// Compilation with warnings (e.g. ESLint).
6963
function handleWarnings({ text }: { text: string[] }) {
7064
clearOutdatedErrors();
7165

72-
const isHotUpdate = !isFirstCompilation;
73-
isFirstCompilation = false;
7466
hasCompileErrors = false;
7567

7668
for (let i = 0; i < text.length; i++) {
@@ -83,17 +75,13 @@ function handleWarnings({ text }: { text: string[] }) {
8375
console.warn(text[i]);
8476
}
8577

86-
// Attempt to apply hot updates or reload.
87-
if (isHotUpdate) {
88-
tryApplyUpdates();
89-
}
78+
tryApplyUpdates();
9079
}
9180

9281
// Compilation with errors (e.g. syntax error or missing modules).
9382
function handleErrors({ text, html }: { text: string[]; html: string }) {
9483
clearOutdatedErrors();
9584

96-
isFirstCompilation = false;
9785
hasCompileErrors = true;
9886

9987
// Also log them to the console.

packages/core/src/defaultConfig.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ export const withDefaultConfig = async (
272272
}
273273
}
274274

275+
if (merged.dev?.lazyCompilation === undefined) {
276+
merged.dev ||= {};
277+
merged.dev.lazyCompilation = {
278+
imports: true,
279+
entries: false,
280+
};
281+
}
282+
275283
if (!merged.source.tsconfigPath) {
276284
const tsconfigPath = join(rootPath, TS_CONFIG_FILE);
277285

packages/core/tests/__snapshots__/builder.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ exports[`should use Rspack as the default bundler > apply Rspack correctly 1`] =
1111
},
1212
"experiments": {
1313
"asyncWebAssembly": true,
14+
"lazyCompilation": {
15+
"entries": false,
16+
"imports": true,
17+
},
1418
"rspackFuture": {
1519
"bundlerInfo": {
1620
"force": false,

packages/core/tests/__snapshots__/default.test.ts.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
1111
},
1212
"experiments": {
1313
"asyncWebAssembly": true,
14+
"lazyCompilation": {
15+
"entries": false,
16+
"imports": true,
17+
},
1418
"rspackFuture": {
1519
"bundlerInfo": {
1620
"force": false,
@@ -517,6 +521,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
517521
},
518522
"experiments": {
519523
"asyncWebAssembly": true,
524+
"lazyCompilation": {
525+
"entries": false,
526+
"imports": true,
527+
},
520528
"rspackFuture": {
521529
"bundlerInfo": {
522530
"force": false,
@@ -1480,6 +1488,10 @@ exports[`tools.rspack > should match snapshot 1`] = `
14801488
},
14811489
"experiments": {
14821490
"asyncWebAssembly": true,
1491+
"lazyCompilation": {
1492+
"entries": false,
1493+
"imports": true,
1494+
},
14831495
"rspackFuture": {
14841496
"bundlerInfo": {
14851497
"force": false,

packages/core/tests/__snapshots__/environments.test.ts.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ exports[`environment config > should print environment config when inspect confi
306306
"reconnect": 100,
307307
},
308308
"hmr": true,
309+
"lazyCompilation": {
310+
"entries": false,
311+
"imports": true,
312+
},
309313
"liveReload": true,
310314
"watchFiles": [],
311315
"writeToDisk": false,
@@ -448,6 +452,10 @@ exports[`environment config > should print environment config when inspect confi
448452
"reconnect": 100,
449453
},
450454
"hmr": true,
455+
"lazyCompilation": {
456+
"entries": false,
457+
"imports": true,
458+
},
451459
"liveReload": true,
452460
"watchFiles": [],
453461
"writeToDisk": false,
@@ -610,6 +618,10 @@ exports[`environment config > should support modify environment config by api.mo
610618
"reconnect": 100,
611619
},
612620
"hmr": true,
621+
"lazyCompilation": {
622+
"entries": false,
623+
"imports": true,
624+
},
613625
"liveReload": true,
614626
"watchFiles": [],
615627
"writeToDisk": false,
@@ -752,6 +764,10 @@ exports[`environment config > should support modify environment config by api.mo
752764
"reconnect": 100,
753765
},
754766
"hmr": true,
767+
"lazyCompilation": {
768+
"entries": false,
769+
"imports": true,
770+
},
755771
"liveReload": true,
756772
"watchFiles": [],
757773
"writeToDisk": false,
@@ -895,6 +911,10 @@ exports[`environment config > should support modify environment config by api.mo
895911
"reconnect": 100,
896912
},
897913
"hmr": true,
914+
"lazyCompilation": {
915+
"entries": false,
916+
"imports": true,
917+
},
898918
"liveReload": true,
899919
"watchFiles": [],
900920
"writeToDisk": false,
@@ -1041,6 +1061,10 @@ exports[`environment config > should support modify single environment config by
10411061
"reconnect": 100,
10421062
},
10431063
"hmr": true,
1064+
"lazyCompilation": {
1065+
"entries": false,
1066+
"imports": true,
1067+
},
10441068
"liveReload": true,
10451069
"watchFiles": [],
10461070
"writeToDisk": false,
@@ -1183,6 +1207,10 @@ exports[`environment config > should support modify single environment config by
11831207
"reconnect": 100,
11841208
},
11851209
"hmr": true,
1210+
"lazyCompilation": {
1211+
"entries": false,
1212+
"imports": true,
1213+
},
11861214
"liveReload": true,
11871215
"watchFiles": [],
11881216
"writeToDisk": false,
@@ -1324,6 +1352,10 @@ exports[`environment config > tools.rspack / bundlerChain can be configured in e
13241352
"devtool": "eval-source-map",
13251353
"experiments": {
13261354
"asyncWebAssembly": true,
1355+
"lazyCompilation": {
1356+
"entries": false,
1357+
"imports": true,
1358+
},
13271359
"rspackFuture": {
13281360
"bundlerInfo": {
13291361
"force": false,

0 commit comments

Comments
 (0)