Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/core/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
17 changes: 10 additions & 7 deletions website/docs/en/config/tools/bundler-chain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -91,14 +91,17 @@ 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 {
tools: {
bundlerChain: (chain, { target }) => {
if (target === 'node') {
// ...
return;
}
},
},
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 10 additions & 6 deletions website/docs/en/config/tools/rspack.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -144,14 +144,18 @@ 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 {
tools: {
rspack: (config, { target }) => {
if (target === 'node') {
// ...
config.plugins.push(new SomePluginForNode());
return config;
}
return config;
},
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
15 changes: 9 additions & 6 deletions website/docs/zh/config/tools/bundler-chain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default {

- **类型:** `boolean`

用于判断当前是否为开发模式构建,比如:
一个布尔值,表示当前是否为开发模式构建,当 [mode](/config/mode) 为 `development` 时,值为 `true`。

```js
export default {
Expand All @@ -73,7 +73,7 @@ export default {

- **类型:** `boolean`

用于判断当前是否为生产模式构建,比如:
一个布尔值,表示当前是否为生产模式构建,当 [mode](/config/mode) 为 `production` 时,值为 `true`。

```js
export default {
Expand All @@ -91,14 +91,17 @@ export default {

- **类型:** `'web' | 'node' | 'web-worker'`

通过 target 参数可以判断构建的目标运行时环境。比如:
当前 [构建目标](/config/output/target)。

你可以为不同的构建目标设置不同的 Rspack 配置,比如:

```js
export default {
tools: {
bundlerChain: (chain, { target }) => {
if (target === 'node') {
// ...
return;
}
},
},
Expand All @@ -109,7 +112,7 @@ export default {

- **类型:** `boolean`

判断当前构建的目标运行时环境是否为 `node`,等价于 `target === 'node'`。
一个布尔值,表示当前 [构建目标](/config/output/target) 是否为 `node`,等价于 `target === 'node'`。

```js
export default {
Expand All @@ -127,7 +130,7 @@ export default {

- **类型:** `boolean`

判断当前构建的目标运行时环境是否为 `web-worker`,等价于 `target === 'web-worker'`。
一个布尔值,表示当前 [构建目标](/config/output/target) 是否为 `web-worker`,等价于 `target === 'web-worker'`。

```js
export default {
Expand All @@ -145,7 +148,7 @@ export default {

- **类型:** `Rspack`

通过这个参数你可以拿到 Rspack 实例。比如:
Rspack 实例,等价于 `import { rspack } from '@rsbuild/core'`。

```js
export default {
Expand Down
16 changes: 10 additions & 6 deletions website/docs/zh/config/tools/rspack.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default {

- **类型:** `boolean`

用于判断当前是否为开发模式构建,比如:
一个布尔值,表示当前是否为开发模式构建,当 [mode](/config/mode) 为 `development` 时,值为 `true`。

```js
export default {
Expand All @@ -126,7 +126,7 @@ export default {

- **类型:** `boolean`

用于判断当前是否为生产模式构建,比如:
一个布尔值,表示当前是否为生产模式构建,当 [mode](/config/mode) 为 `production` 时,值为 `true`。

```js
export default {
Expand All @@ -144,14 +144,18 @@ export default {

- **类型:** `'web' | 'node' | 'web-worker'`

通过 target 参数可以判断构建的目标运行时环境。比如:
当前 [构建目标](/config/output/target)。

你可以为不同的构建目标设置不同的 Rspack 配置,比如:

```js
export default {
tools: {
rspack: (config, { target }) => {
if (target === 'node') {
// ...
config.plugins.push(new SomePluginForNode());
return config;
}
return config;
},
Expand All @@ -163,7 +167,7 @@ export default {

- **类型:** `boolean`

判断当前构建的目标运行时环境是否为 `node`,等价于 `target === 'node'`。
一个布尔值,表示当前 [构建目标](/config/output/target) 是否为 `node`,等价于 `target === 'node'`。

```js
export default {
Expand All @@ -182,7 +186,7 @@ export default {

- **类型:** `boolean`

判断当前构建的目标运行时环境是否为 `web-worker`,等价于 `target === 'web-worker'`。
一个布尔值,表示当前 [构建目标](/config/output/target) 是否为 `web-worker`,等价于 `target === 'web-worker'`。

```js
export default {
Expand All @@ -201,7 +205,7 @@ export default {

- **类型:** `Rspack`

通过这个参数你可以拿到 Rspack 实例。比如:
Rspack 实例,等价于 `import { rspack } from '@rsbuild/core'`。

```js
export default {
Expand Down
Loading