Skip to content

Commit 479c1e3

Browse files
fix: update lazyCompilation config to fix deprecation warning (#5829)
Co-authored-by: qixuan <[email protected]>
1 parent 0bdbcfa commit 479c1e3

File tree

9 files changed

+46
-59
lines changed

9 files changed

+46
-59
lines changed

e2e/cases/lazy-compilation/basic/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ rspackOnlyTest(
4848
rsbuildConfig: {
4949
tools: {
5050
rspack: {
51-
experiments: {
52-
lazyCompilation: true,
53-
},
51+
lazyCompilation: true,
5452
},
5553
},
5654
},

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
2424
},
2525
"experiments": {
2626
"asyncWebAssembly": true,
27-
"lazyCompilation": {
28-
"entries": false,
29-
"imports": true,
30-
},
3127
},
3228
"infrastructureLogging": {
3329
"level": "error",
@@ -486,10 +482,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ
486482
},
487483
"experiments": {
488484
"asyncWebAssembly": true,
489-
"lazyCompilation": {
490-
"entries": false,
491-
"imports": true,
492-
},
493485
},
494486
"infrastructureLogging": {
495487
"level": "error",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"reduce-configs": "^1.1.1",
8989
"rsbuild-dev-middleware": "0.3.0",
9090
"rslog": "^1.2.11",
91-
"rspack-chain": "^1.3.2",
91+
"rspack-chain": "^1.4.0",
9292
"rspack-manifest-plugin": "5.0.3",
9393
"sirv": "^3.0.1",
9494
"style-loader": "3.3.4",

packages/core/src/plugins/lazyCompilation.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const pluginLazyCompilation = (): RsbuildPlugin => ({
88

99
setup(api) {
1010
api.modifyBundlerChain((chain, { environment, target }) => {
11-
if (target !== 'web') {
11+
if (target !== 'web' || api.context.bundlerType === 'webpack') {
1212
return;
1313
}
1414

@@ -25,12 +25,9 @@ export const pluginLazyCompilation = (): RsbuildPlugin => ({
2525
// If there is only one entry, do not enable lazy compilation for entries
2626
// this can reduce the rebuild time
2727
if (Object.keys(entries).length <= 1) {
28-
chain.experiments({
29-
...chain.get('experiments'),
30-
lazyCompilation: {
31-
entries: false,
32-
imports: true,
33-
},
28+
chain.lazyCompilation({
29+
entries: false,
30+
imports: true,
3431
});
3532
return;
3633
}
@@ -42,23 +39,17 @@ export const pluginLazyCompilation = (): RsbuildPlugin => ({
4239
typeof options.serverUrl === 'string' &&
4340
api.context.devServer
4441
) {
45-
chain.experiments({
46-
...chain.get('experiments'),
47-
lazyCompilation: {
48-
...options,
49-
serverUrl: replacePortPlaceholder(
50-
options.serverUrl,
51-
api.context.devServer.port,
52-
),
53-
},
42+
chain.lazyCompilation({
43+
...options,
44+
serverUrl: replacePortPlaceholder(
45+
options.serverUrl,
46+
api.context.devServer.port,
47+
),
5448
});
5549
return;
5650
}
5751

58-
chain.experiments({
59-
...chain.get('experiments'),
60-
lazyCompilation: options,
61-
});
52+
chain.lazyCompilation(options);
6253
});
6354
},
6455
});

packages/core/src/server/devMiddlewares.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,19 @@ const applyDefaultMiddlewares = async ({
135135
// Rsbuild users can enable lazy compilation in two ways:
136136
// 1. Use Rsbuild's `dev.lazyCompilation` option
137137
// 2. Use Rspack's `experiments.lazyCompilation` option
138+
// 3. Use Rspack's configuration top-level `lazyCompilation` option
138139
const isLazyCompilationEnabled = () => {
139140
if (isMultiCompiler(compiler)) {
140141
return compiler.compilers.some(
141-
(childCompiler) => childCompiler.options.experiments?.lazyCompilation,
142+
(childCompiler) =>
143+
childCompiler.options.experiments?.lazyCompilation ||
144+
childCompiler.options.lazyCompilation,
142145
);
143146
}
144-
return compiler.options.experiments?.lazyCompilation;
147+
return (
148+
compiler.options.experiments?.lazyCompilation ||
149+
compiler.options.lazyCompilation
150+
);
145151
};
146152

147153
if (isLazyCompilationEnabled()) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ 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-
},
1814
"rspackFuture": {
1915
"bundlerInfo": {
2016
"force": false,
@@ -25,6 +21,10 @@ exports[`should use Rspack as the default bundler > apply Rspack correctly 1`] =
2521
"infrastructureLogging": {
2622
"level": "error",
2723
},
24+
"lazyCompilation": {
25+
"entries": false,
26+
"imports": true,
27+
},
2828
"mode": "development",
2929
"module": {
3030
"parser": {

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
1111
},
1212
"experiments": {
1313
"asyncWebAssembly": true,
14-
"lazyCompilation": {
15-
"entries": false,
16-
"imports": true,
17-
},
1814
"rspackFuture": {
1915
"bundlerInfo": {
2016
"force": false,
@@ -25,6 +21,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
2521
"infrastructureLogging": {
2622
"level": "error",
2723
},
24+
"lazyCompilation": {
25+
"entries": false,
26+
"imports": true,
27+
},
2828
"mode": "development",
2929
"module": {
3030
"parser": {
@@ -521,10 +521,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
521521
},
522522
"experiments": {
523523
"asyncWebAssembly": true,
524-
"lazyCompilation": {
525-
"entries": false,
526-
"imports": true,
527-
},
528524
"rspackFuture": {
529525
"bundlerInfo": {
530526
"force": false,
@@ -535,6 +531,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
535531
"infrastructureLogging": {
536532
"level": "error",
537533
},
534+
"lazyCompilation": {
535+
"entries": false,
536+
"imports": true,
537+
},
538538
"mode": "production",
539539
"module": {
540540
"parser": {
@@ -1488,10 +1488,6 @@ exports[`tools.rspack > should match snapshot 1`] = `
14881488
},
14891489
"experiments": {
14901490
"asyncWebAssembly": true,
1491-
"lazyCompilation": {
1492-
"entries": false,
1493-
"imports": true,
1494-
},
14951491
"rspackFuture": {
14961492
"bundlerInfo": {
14971493
"force": false,
@@ -1502,6 +1498,10 @@ exports[`tools.rspack > should match snapshot 1`] = `
15021498
"infrastructureLogging": {
15031499
"level": "error",
15041500
},
1501+
"lazyCompilation": {
1502+
"entries": false,
1503+
"imports": true,
1504+
},
15051505
"mode": "development",
15061506
"module": {
15071507
"parser": {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,10 +1352,6 @@ exports[`environment config > tools.rspack / bundlerChain can be configured in e
13521352
"devtool": "eval-source-map",
13531353
"experiments": {
13541354
"asyncWebAssembly": true,
1355-
"lazyCompilation": {
1356-
"entries": false,
1357-
"imports": true,
1358-
},
13591355
"rspackFuture": {
13601356
"bundlerInfo": {
13611357
"force": false,
@@ -1366,6 +1362,10 @@ exports[`environment config > tools.rspack / bundlerChain can be configured in e
13661362
"infrastructureLogging": {
13671363
"level": "error",
13681364
},
1365+
"lazyCompilation": {
1366+
"entries": false,
1367+
"imports": true,
1368+
},
13691369
"mode": "development",
13701370
"module": {
13711371
"parser": {

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)