Skip to content

Commit

Permalink
chore: experiments.lazyCompilation can be used in rspack (#5780)
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy committed May 28, 2024
1 parent e8d41fe commit cdc4758
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 19 deletions.
5 changes: 5 additions & 0 deletions packages/cli/uni-builder/src/rspack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export async function parseConfig(
options,
);

if (uniBuilderConfig.experiments?.lazyCompilation) {
rsbuildConfig.dev!.lazyCompilation =
uniBuilderConfig.experiments.lazyCompilation;
}

if (uniBuilderConfig.tools?.babel) {
const { pluginBabel } = await import('@rsbuild/plugin-babel');
const { pluginBabelPost } = await import('./plugins/babel-post');
Expand Down
6 changes: 1 addition & 5 deletions packages/cli/uni-builder/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
import type { RsbuildConfig } from '@rsbuild/core';
import type { PluginAssetsRetryOptions } from '@rsbuild/plugin-assets-retry';
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
import type { LazyCompilationOptions } from './webpack/plugins/lazyCompilation';
import type { PluginRemOptions } from '@rsbuild/plugin-rem';
import type { PluginTsLoaderOptions } from './webpack/plugins/tsLoader';
import type { SvgDefaultExport } from '@rsbuild/plugin-svgr';
Expand Down Expand Up @@ -312,10 +311,7 @@ export type UniBuilderExtraConfig = {
checkSyntax?: boolean | PluginCheckSyntaxOptions;
};
experiments?: {
/**
* Tips: this configuration is not yet supported in rspack
*/
lazyCompilation?: LazyCompilationOptions;
lazyCompilation?: DevConfig['lazyCompilation'];
/**
* Enable the ability for source code building
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { RsbuildPlugin } from '@rsbuild/core';
import type { DevConfig } from '@rsbuild/shared';

export type LazyCompilationOptions =
| boolean
| {
entries?: boolean;
imports?: boolean;
};
type LazyCompilationOptions = DevConfig['lazyCompilation'];

export const pluginLazyCompilation = (
options: LazyCompilationOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ type LazyCompilationOptions =
entries?: boolean;
// Whether to enable lazy compilation for dynamic imports
imports?: boolean;
// Specify which imported modules should be lazily compiled.
test?: RegExp | ((m: Module) => boolean);
};
```

- **Default:** `false`
- **Bundler:** `only support webpack`

Used to enable the lazy compilation (i.e. compile on demand). When this config is enabled, Builder will compile entrypoints and dynamic imports only when they are used. It will improve the compilation startup time of the project.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ Unsupported configurations and capabilities include:

> Experimental related configurations in the Builder
Unsupported configurations and capabilities include:

- [experiments.lazyCompilation](/api/config-experiments.html#experimentslazycompilation)
All configurations and capabilities under experimental are available within rspack.

#### Performance Config

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ type LazyCompilationOptions =
imports?: boolean;
// 是否为入口模块开启延迟编译
entries?: boolean;
// 指定哪些导入的模块应该被延迟编译
test?: RegExp | ((m: Module) => boolean);
};
```

- **默认值:** `false`
- **打包工具:** `仅支持 webpack`

用于开启延迟编译(即按需编译)的能力。当开启此配置项时,Builder 会进行延迟编译,提升项目的编译启动速度。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ Builder 旨在消除不同打包工具之间的主要差异,帮助用户以较

> Builder 中的一些实验性配置。
不支持的配置项及能力包括:

- [experiments.lazyCompilation](/api/config-experiments.html#experimentslazycompilation)
所有 experiments 下的配置项及能力在 Rspack 内均可使用。

#### Performance Config

Expand Down

0 comments on commit cdc4758

Please sign in to comment.