diff --git a/packages/core/src/plugins/lazyCompilation.ts b/packages/core/src/plugins/lazyCompilation.ts index 7f7ef6245b..ef8e0a3748 100644 --- a/packages/core/src/plugins/lazyCompilation.ts +++ b/packages/core/src/plugins/lazyCompilation.ts @@ -16,10 +16,26 @@ export const pluginLazyCompilation = (): RsbuildPlugin => ({ return; } - chain.experiments({ - ...chain.get('experiments'), - lazyCompilation: options, - }); + if (options === true) { + const entries = chain.entryPoints.entries() || {}; + + // If there is only one entry, do not enable lazy compilation for entries + // this can reduce the rebuild time + if (Object.keys(entries).length <= 1) { + chain.experiments({ + ...chain.get('experiments'), + lazyCompilation: { + entries: false, + imports: true, + }, + }); + } + } else { + chain.experiments({ + ...chain.get('experiments'), + lazyCompilation: options, + }); + } }); }, }); diff --git a/website/docs/en/config/dev/lazy-compilation.mdx b/website/docs/en/config/dev/lazy-compilation.mdx index 3d778c59a2..4d8b9e7729 100644 --- a/website/docs/en/config/dev/lazy-compilation.mdx +++ b/website/docs/en/config/dev/lazy-compilation.mdx @@ -63,6 +63,7 @@ export default { dev: { lazyCompilation: { imports: true, + // If there is only one entry, Rsbuild will not enable the entries option by default entries: true, }, }, diff --git a/website/docs/zh/config/dev/lazy-compilation.mdx b/website/docs/zh/config/dev/lazy-compilation.mdx index 7bd0160f2b..bdfd11c6cf 100644 --- a/website/docs/zh/config/dev/lazy-compilation.mdx +++ b/website/docs/zh/config/dev/lazy-compilation.mdx @@ -63,6 +63,7 @@ export default { dev: { lazyCompilation: { imports: true, + // 如果只有一个入口,则 Rsbuild 默认不启用 entries 选项 entries: true, }, },