diff --git a/packages/core/src/types/hooks.ts b/packages/core/src/types/hooks.ts index 5fb22c7091..b2a85ba799 100644 --- a/packages/core/src/types/hooks.ts +++ b/packages/core/src/types/hooks.ts @@ -224,14 +224,45 @@ export type ModifyChainUtils = { * The value of `process.env.NODE_ENV` */ env: string; + /** + * A boolean value indicating whether this is a development build. + * Set to `true` when the `mode` is `development`. + */ isDev: boolean; + /** + * A boolean value indicating whether this is a production build. + * Set to `true` when the `mode` is `production`. + */ isProd: boolean; + /** + * The current build target. + */ target: RsbuildTarget; + /** + * A boolean value indicating whether the build target is `node`. + * Equivalent to `target === 'node'`. + */ isServer: boolean; + /** + * A boolean value indicating whether the build target is `web-worker`. + * Equivalent to `target === 'web-worker'`. + */ isWebWorker: boolean; + /** + * Predefined chain IDs. + */ CHAIN_ID: ChainIdentifier; + /** + * The environment context for current build. + */ environment: EnvironmentContext; + /** + * The Rspack instance, same as `import { rspack } from '@rsbuild/core'`. + */ rspack: typeof rspack; + /** + * The default export of `html-rspack-plugin`. + */ HtmlPlugin: typeof HtmlRspackPlugin; }; diff --git a/website/docs/en/config/tools/bundler-chain.mdx b/website/docs/en/config/tools/bundler-chain.mdx index a945fb6ae1..2ede8ea66e 100644 --- a/website/docs/en/config/tools/bundler-chain.mdx +++ b/website/docs/en/config/tools/bundler-chain.mdx @@ -54,7 +54,7 @@ export default { - **Type:** `boolean` -Used to determine whether the current build is a development build, such as: +A boolean value indicating whether this is a development build. Set to `true` when the [mode](/config/mode) is `development`. ```js export default { @@ -73,7 +73,7 @@ export default { - **Type:** `boolean` -Used to determine whether the current build is a production build, such as: +A boolean value indicating whether this is a production build. Set to `true` when the [mode](/config/mode) is `production`. ```js export default { @@ -91,7 +91,9 @@ export default { - **Type:** `'web' | 'node' | 'web-worker'` -The `target` parameter can be used to determine the build target environment. For example: +The current [build target](/config/output/target). + +You can set different Rspack configurations for different build targets, for example: ```js export default { @@ -99,6 +101,7 @@ export default { bundlerChain: (chain, { target }) => { if (target === 'node') { // ... + return; } }, }, @@ -109,7 +112,7 @@ export default { - **Type:** `boolean` -Determines whether the target environment is `node`, equivalent to `target === 'node'`. +A boolean value indicating whether the [build target](/config/output/target) is `node`, equivalent to `target === 'node'`. ```js export default { @@ -127,7 +130,7 @@ export default { - **Type:** `boolean` -Determines whether the target environment is `web-worker`, equivalent to `target === 'web-worker'`. +A boolean value indicating whether the [build target](/config/output/target) is `web-worker`, equivalent to `target === 'web-worker'`. ```js export default { @@ -145,7 +148,7 @@ export default { - **Type:** `Rspack` -The Rspack instance. For example: +The Rspack instance, same as `import { rspack } from '@rsbuild/core'`. ```js export default { @@ -181,7 +184,7 @@ export default { ## CHAIN_ID -Some common Chain IDs are predefined in the Rsbuild, and you can use these IDs to locate the built-in Rule or Plugin. +Some common chain IDs are predefined in the Rsbuild, and you can use these IDs to locate the built-in Rule or Plugin. :::tip Please note that some of the rules or plugins listed below are not available by default. They will only be included in the Rspack or webpack configuration when you enable specific options or register certain plugins. diff --git a/website/docs/en/config/tools/rspack.mdx b/website/docs/en/config/tools/rspack.mdx index 62d583a37a..243f942115 100644 --- a/website/docs/en/config/tools/rspack.mdx +++ b/website/docs/en/config/tools/rspack.mdx @@ -107,7 +107,7 @@ export default { - **Type:** `boolean` -Used to determine whether the current build is a development build, such as: +A boolean value indicating whether this is a development build. Set to `true` when the [mode](/config/mode) is `development`. ```js export default { @@ -126,7 +126,7 @@ export default { - **Type:** `boolean` -Used to determine whether the current build is a production build, such as: +A boolean value indicating whether this is a production build. Set to `true` when the [mode](/config/mode) is `production`. ```js export default { @@ -144,7 +144,9 @@ export default { - **Type:** `'web' | 'node' | 'web-worker'` -The `target` parameter can be used to determine the build target environment. For example: +The current [build target](/config/output/target). + +You can set different Rspack configurations for different build targets, for example: ```js export default { @@ -152,6 +154,8 @@ export default { rspack: (config, { target }) => { if (target === 'node') { // ... + config.plugins.push(new SomePluginForNode()); + return config; } return config; }, @@ -163,7 +167,7 @@ export default { - **Type:** `boolean` -Determines whether the target environment is `node`, equivalent to `target === 'node'`. +A boolean value indicating whether the [build target](/config/output/target) is `node`, equivalent to `target === 'node'`. ```js export default { @@ -182,7 +186,7 @@ export default { - **Type:** `boolean` -Determines whether the target environment is `web-worker`, equivalent to `target === 'web-worker'`. +A boolean value indicating whether the [build target](/config/output/target) is `web-worker`, equivalent to `target === 'web-worker'`. ```js export default { @@ -201,7 +205,7 @@ export default { - **Type:** `Rspack` -The Rspack instance. For example: +The Rspack instance, same as `import { rspack } from '@rsbuild/core'`. ```js export default { diff --git a/website/docs/zh/config/tools/bundler-chain.mdx b/website/docs/zh/config/tools/bundler-chain.mdx index 978c938548..bf810834c9 100644 --- a/website/docs/zh/config/tools/bundler-chain.mdx +++ b/website/docs/zh/config/tools/bundler-chain.mdx @@ -54,7 +54,7 @@ export default { - **类型:** `boolean` -用于判断当前是否为开发模式构建,比如: +一个布尔值,表示当前是否为开发模式构建,当 [mode](/config/mode) 为 `development` 时,值为 `true`。 ```js export default { @@ -73,7 +73,7 @@ export default { - **类型:** `boolean` -用于判断当前是否为生产模式构建,比如: +一个布尔值,表示当前是否为生产模式构建,当 [mode](/config/mode) 为 `production` 时,值为 `true`。 ```js export default { @@ -91,7 +91,9 @@ export default { - **类型:** `'web' | 'node' | 'web-worker'` -通过 target 参数可以判断构建的目标运行时环境。比如: +当前 [构建目标](/config/output/target)。 + +你可以为不同的构建目标设置不同的 Rspack 配置,比如: ```js export default { @@ -99,6 +101,7 @@ export default { bundlerChain: (chain, { target }) => { if (target === 'node') { // ... + return; } }, }, @@ -109,7 +112,7 @@ export default { - **类型:** `boolean` -判断当前构建的目标运行时环境是否为 `node`,等价于 `target === 'node'`。 +一个布尔值,表示当前 [构建目标](/config/output/target) 是否为 `node`,等价于 `target === 'node'`。 ```js export default { @@ -127,7 +130,7 @@ export default { - **类型:** `boolean` -判断当前构建的目标运行时环境是否为 `web-worker`,等价于 `target === 'web-worker'`。 +一个布尔值,表示当前 [构建目标](/config/output/target) 是否为 `web-worker`,等价于 `target === 'web-worker'`。 ```js export default { @@ -145,7 +148,7 @@ export default { - **类型:** `Rspack` -通过这个参数你可以拿到 Rspack 实例。比如: +Rspack 实例,等价于 `import { rspack } from '@rsbuild/core'`。 ```js export default { diff --git a/website/docs/zh/config/tools/rspack.mdx b/website/docs/zh/config/tools/rspack.mdx index ad2cc10145..963451abd8 100644 --- a/website/docs/zh/config/tools/rspack.mdx +++ b/website/docs/zh/config/tools/rspack.mdx @@ -107,7 +107,7 @@ export default { - **类型:** `boolean` -用于判断当前是否为开发模式构建,比如: +一个布尔值,表示当前是否为开发模式构建,当 [mode](/config/mode) 为 `development` 时,值为 `true`。 ```js export default { @@ -126,7 +126,7 @@ export default { - **类型:** `boolean` -用于判断当前是否为生产模式构建,比如: +一个布尔值,表示当前是否为生产模式构建,当 [mode](/config/mode) 为 `production` 时,值为 `true`。 ```js export default { @@ -144,7 +144,9 @@ export default { - **类型:** `'web' | 'node' | 'web-worker'` -通过 target 参数可以判断构建的目标运行时环境。比如: +当前 [构建目标](/config/output/target)。 + +你可以为不同的构建目标设置不同的 Rspack 配置,比如: ```js export default { @@ -152,6 +154,8 @@ export default { rspack: (config, { target }) => { if (target === 'node') { // ... + config.plugins.push(new SomePluginForNode()); + return config; } return config; }, @@ -163,7 +167,7 @@ export default { - **类型:** `boolean` -判断当前构建的目标运行时环境是否为 `node`,等价于 `target === 'node'`。 +一个布尔值,表示当前 [构建目标](/config/output/target) 是否为 `node`,等价于 `target === 'node'`。 ```js export default { @@ -182,7 +186,7 @@ export default { - **类型:** `boolean` -判断当前构建的目标运行时环境是否为 `web-worker`,等价于 `target === 'web-worker'`。 +一个布尔值,表示当前 [构建目标](/config/output/target) 是否为 `web-worker`,等价于 `target === 'web-worker'`。 ```js export default { @@ -201,7 +205,7 @@ export default { - **类型:** `Rspack` -通过这个参数你可以拿到 Rspack 实例。比如: +Rspack 实例,等价于 `import { rspack } from '@rsbuild/core'`。 ```js export default {