diff --git a/website/docs/en/blog/announcing-1-6.mdx b/website/docs/en/blog/announcing-1-6.mdx index 9f9f3a93b919..86965f3b5cf5 100644 --- a/website/docs/en/blog/announcing-1-6.mdx +++ b/website/docs/en/blog/announcing-1-6.mdx @@ -41,7 +41,7 @@ Rspack 1.6 improved tree shaking support for dynamic imports. In previous versio Now, Rspack introduces comprehensive static analysis for dynamic imports. It can recognize and handle a wider range of usage patterns. This allows Rspack to precisely eliminate unused exports and further reduce the size of the final bundle. -```js title="rspack.config.mjs" +```js // Rspack 1.5 – Only supported destructured imports const { value } = await import('./module'); console.log(value); diff --git a/website/docs/en/config/experiments.mdx b/website/docs/en/config/experiments.mdx index f3ca5c835b96..bf4f08de1d9c 100644 --- a/website/docs/en/config/experiments.mdx +++ b/website/docs/en/config/experiments.mdx @@ -85,66 +85,6 @@ export default { }; ``` -## experiments.topLevelAwait - -:::warning - -This option has been deprecated and will be removed in Rspack v2.0. - -Top-level await will always be enabled in the future. Remove this option from your Rspack configuration. - -::: - -- **Type:** `boolean` -- **Default:** `true` - -Enables support for [Top-level await](https://github.com/tc39/proposal-top-level-await). Top-level await can only be used in modules with [ModuleType](/config/module#ruletype) set to `javascript/esm`. - -Enabled by default. Can be disabled with this configuration: - -```js title="rspack.config.mjs" -export default { - experiments: { - topLevelAwait: false, - }, -}; -``` - -## experiments.lazyCompilation - - - -:::warning - -This configuration has been deprecated. Please use [lazyCompilation](/config/lazy-compilation) instead. - -::: - -## experiments.layers - - - -- **Type:** `boolean` -- **Default:** `false` - -:::warning -This option is deprecated. Layers are now always enabled. Remove this option from your Rspack configuration. -::: - -Controls whether to enable the layer feature. Layers add an identifier prefix to all modules in a subgraph starting from a module in the module graph, to distinguish them from modules in different layers. For example: - -The `layer` of the `index.js` module is `null` by default, and its `identifier` is `./index.js`. If we set `layer = 'client'` for it, its `identifier` becomes `(client)/./index.js`. At this point, the `index.js` modules in these two different layers are treated as distinct modules, because their unique `identifier`s differ. The final output includes the artifacts of both modules. - -By default, a module's layer is `null`, and it inherits its parent module's layer. You can add a layer to an entry module using `entryOptions.layer`, and add a layer to matched modules using [`module.rule[].layer`](/config/module#rulelayer). Additionally, you can match based on the parent module's layer using [`module.rule[].issuerLayer`](/config/module#ruleissuerlayer). - -```js title="rspack.config.mjs" -export default { - experiments: { - layers: true, - }, -}; -``` - ## experiments.incremental @@ -904,3 +844,71 @@ A side-effect-free module is a module that meets one of the following conditions - **Default:** `false` When enabled, Rspack will support bundling the [Deferred Imports Evaluation](https://github.com/tc39/proposal-defer-import-eval) proposal, which allows deferring the evaluation of a module until its first use. Currently, only `import defer * as ns from "./module"` is supported, while `import.defer()` will be supported in future versions. + +```js title="rspack.config.mjs" +export default { + experiments: { + deferImport: true, + }, +}; +``` + +## experiments.topLevelAwait + +:::warning + +This option has been deprecated and will be removed in Rspack v2.0. + +Top-level await will always be enabled in the future. Remove this option from your Rspack configuration. + +::: + +- **Type:** `boolean` +- **Default:** `true` + +Enables support for [Top-level await](https://github.com/tc39/proposal-top-level-await). Top-level await can only be used in modules with [ModuleType](/config/module#ruletype) set to `javascript/esm`. + +Enabled by default. Can be disabled with this configuration: + +```js title="rspack.config.mjs" +export default { + experiments: { + topLevelAwait: false, + }, +}; +``` + +## experiments.lazyCompilation + + + +:::warning + +This configuration has been deprecated. Please use [lazyCompilation](/config/lazy-compilation) instead. + +::: + +## experiments.layers + + + +- **Type:** `boolean` +- **Default:** `false` + +:::warning +This option is deprecated. Layers are now always enabled. Remove this option from your Rspack configuration. +::: + +Controls whether to enable the layer feature. Layers add an identifier prefix to all modules in a subgraph starting from a module in the module graph, to distinguish them from modules in different layers. For example: + +The `layer` of the `index.js` module is `null` by default, and its `identifier` is `./index.js`. If we set `layer = 'client'` for it, its `identifier` becomes `(client)/./index.js`. At this point, the `index.js` modules in these two different layers are treated as distinct modules, because their unique `identifier`s differ. The final output includes the artifacts of both modules. + +By default, a module's layer is `null`, and it inherits its parent module's layer. You can add a layer to an entry module using `entryOptions.layer`, and add a layer to matched modules using [`module.rule[].layer`](/config/module#rulelayer). Additionally, you can match based on the parent module's layer using [`module.rule[].issuerLayer`](/config/module#ruleissuerlayer). + +```js title="rspack.config.mjs" +export default { + experiments: { + layers: true, + }, +}; +``` diff --git a/website/docs/zh/blog/announcing-1-6.mdx b/website/docs/zh/blog/announcing-1-6.mdx index f64b375b0e6f..17cc8f34b37c 100644 --- a/website/docs/zh/blog/announcing-1-6.mdx +++ b/website/docs/zh/blog/announcing-1-6.mdx @@ -41,7 +41,7 @@ Rspack 1.6 增强了对动态导入 tree shaking 的支持。在此前的版本 现在,Rspack 为动态导入引入了更全面的静态分析,能够识别并处理多种使用模式,从而精准地移除未被使用的导出内容,进一步减小最终打包产物的体积。 -```js title="rspack.config.mjs" +```js // Rspack 1.5 - 仅支持分析解构赋值 const { value } = await import('./module'); console.log(value); diff --git a/website/docs/zh/config/experiments.mdx b/website/docs/zh/config/experiments.mdx index 52afc54c8185..d93a73cf1619 100644 --- a/website/docs/zh/config/experiments.mdx +++ b/website/docs/zh/config/experiments.mdx @@ -86,66 +86,6 @@ export default { }; ``` -## experiments.topLevelAwait - -:::warning - -该配置项已经废弃,将在 Rspack v2.0 中被移除。 - -未来 `Top-level await` 特性将会始终开启,请从 Rspack 配置中移除此选项。 - -::: - -- **类型:** `boolean` -- **默认值:** `true` - -开启打包 [Top-level await](https://github.com/tc39/proposal-top-level-await) 的支持,`Top-level await` 仅能在 [ModuleType](/config/module#ruletype) 为 `javascript/esm` 的模块中使用。 - -默认开启,可通过该配置关闭: - -```js title="rspack.config.mjs" -export default { - experiments: { - topLevelAwait: false, - }, -}; -``` - -## experiments.lazyCompilation - - - -:::warning - -该配置项已经废弃,请使用 [lazyCompilation](/config/lazy-compilation) 替代此项。 - -::: - -## experiments.layers - - - -- **类型:** `boolean` -- **默认值:** `false` - -:::warning -该配置项已经废弃,layers 特性已始终开启,请从 Rspack 配置项中移除此配置。 -::: - -控制是否启用 layer 功能,layer 可以为模块图中以一个模块作为起点的子图中的所有模块添加标识符前缀,用来与其他不同 layer 的模块进行区分,比如: - -`index.js` 模块的 layer 为默认的 `null`,其 `identifier` 为 `./index.js`,我们为其添加 `layer = 'client'`,其 `identifier` 会变成 `(client)/./index.js`,这时这两个不同 layer 的 `index.js` 会被区分为不同的模块,因为其唯一标识 `identifier` 不一样,最终产物中也会存在这两个模块的产物。 - -模块默认的 layer 为 `null`,模块默认会继承其父模块的 layer,你可以通过 `entryOptions.layer` 为一个入口模块添加 layer,也可以通过 [`module.rule[].layer`](/config/module#rulelayer) 为匹配到的模块添加 layer,同时可以通过 [`module.rule[].issuerLayer`](/config/module#ruleissuerlayer) 根据父模块的 layer 进行匹配。 - -```js title="rspack.config.mjs" -export default { - experiments: { - layers: true, - }, -}; -``` - ## experiments.incremental @@ -905,3 +845,71 @@ export default { - **默认值:** `false` 开启后 Rspack 会支持打包 [Deferred Imports Evaluation](https://github.com/tc39/proposal-defer-import-eval) 提案,该功能允许延迟模块的执行直到首次使用。目前仅支持 `import defer * as ns from "./module"`,`import.defer()` 会在后续版本支持。 + +```js title="rspack.config.mjs" +export default { + experiments: { + deferImport: true, + }, +}; +``` + +## experiments.topLevelAwait + +:::warning + +该配置项已经废弃,将在 Rspack v2.0 中被移除。 + +未来 `Top-level await` 特性将会始终开启,请从 Rspack 配置中移除此选项。 + +::: + +- **类型:** `boolean` +- **默认值:** `true` + +开启打包 [Top-level await](https://github.com/tc39/proposal-top-level-await) 的支持,`Top-level await` 仅能在 [ModuleType](/config/module#ruletype) 为 `javascript/esm` 的模块中使用。 + +默认开启,可通过该配置关闭: + +```js title="rspack.config.mjs" +export default { + experiments: { + topLevelAwait: false, + }, +}; +``` + +## experiments.lazyCompilation + + + +:::warning + +该配置项已经废弃,请使用 [lazyCompilation](/config/lazy-compilation) 替代此项。 + +::: + +## experiments.layers + + + +- **类型:** `boolean` +- **默认值:** `false` + +:::warning +该配置项已经废弃,layers 特性已始终开启,请从 Rspack 配置项中移除此配置。 +::: + +控制是否启用 layer 功能,layer 可以为模块图中以一个模块作为起点的子图中的所有模块添加标识符前缀,用来与其他不同 layer 的模块进行区分,比如: + +`index.js` 模块的 layer 为默认的 `null`,其 `identifier` 为 `./index.js`,我们为其添加 `layer = 'client'`,其 `identifier` 会变成 `(client)/./index.js`,这时这两个不同 layer 的 `index.js` 会被区分为不同的模块,因为其唯一标识 `identifier` 不一样,最终产物中也会存在这两个模块的产物。 + +模块默认的 layer 为 `null`,模块默认会继承其父模块的 layer,你可以通过 `entryOptions.layer` 为一个入口模块添加 layer,也可以通过 [`module.rule[].layer`](/config/module#rulelayer) 为匹配到的模块添加 layer,同时可以通过 [`module.rule[].issuerLayer`](/config/module#ruleissuerlayer) 根据父模块的 layer 进行匹配。 + +```js title="rspack.config.mjs" +export default { + experiments: { + layers: true, + }, +}; +```