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
1 change: 1 addition & 0 deletions website/docs/en/config/rsbuild/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
"resolve",
"source",
"output",
"tools",
Expand Down
2 changes: 1 addition & 1 deletion website/docs/en/config/rsbuild/output.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Whether to emit CSS to the output bundles.

At build time, prevent some `import` dependencies from being packed into bundles in your code, and instead fetch them externally at runtime.

It is important to note that `output.externals` differs from [source.alias](/config/rsbuild/source#sourcealias). Check out [source.alias](/config/rsbuild/source#sourcealias) documentation for more information.
It is important to note that `output.externals` differs from [resolve.alias](/config/rsbuild/resolve#resolvealias). Check out [resolve.alias](/config/rsbuild/resolve#resolvealias) documentation for more information.

## output.filenameHash <RsbuildDocBadge path="/config/output/filename-hash" text="output.filenameHash" />

Expand Down
52 changes: 52 additions & 0 deletions website/docs/en/config/rsbuild/resolve.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { RsbuildDocBadge } from '@components/RsbuildDocBadge';

# resolve

## resolve.aliasStrategy <RsbuildDocBadge path="/config/resolve/alias-strategy" text="resolve.aliasStrategy" />

`resolve.aliasStrategy` is used to control the priority between the `paths` option in `tsconfig.json` and the `alias` option in the bundler.

## resolve.alias <RsbuildDocBadge path="/config/resolve/alias" text="resolve.alias" />

Create aliases to import or require certain modules, same as the [resolve.alias](https://rspack.dev/config/resolve#resolvealias) config of Rspack.

It is important to note that `resolve.alias` differs from [output.externals](/config/rsbuild/output#outputexternals) in the following ways:

- `resolve.alias` allows you to replace the target module you want to include in the output bundles with another module. It only works if [lib.bundle](/config/lib/bundle) is set to `true`.

For example, if you want to replace `lodash` with `lodash-es` in a bundled CLI application, you can configure it as follows:

```ts title="rslib.config.ts"
export default {
// ...
resolve: {
alias: {
lodash: 'lodash-es',
},
},
};
```

All `lodash` modules imported in the source code will be mapped to `lodash-es` and be bundled into the output.

- `output.externals` is used to handle alias mapping for externalized modules. Externalized modules are not included in the bundle; instead, they are imported from external sources at runtime.

For example, if you want to replace `react` and `react-dom` with `preact/compat` in the bundle, you can configure it as follows:

```ts title="rslib.config.ts"
export default {
// ...
output: {
externals: {
react: 'preact/compat',
'react-dom': 'preact/compat',
},
},
};
```

Now, the code `import { useState } from 'react'` will be replaced with `import { useState } from 'preact/compat'`.

## resolve.dedupe <RsbuildDocBadge path="/config/resolve/dedupe" text="resolve.dedupe" />

`resolve.dedupe` is used to resolve the specified packages from project root, which is useful for deduplicating packages and reducing the bundle size.
45 changes: 0 additions & 45 deletions website/docs/en/config/rsbuild/source.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,6 @@ import { RsbuildDocBadge } from '@components/RsbuildDocBadge';

Configure the source code parsing and compilation options.

## source.aliasStrategy <RsbuildDocBadge path="/config/source/alias-strategy" text="source.aliasStrategy" />

`source.aliasStrategy` is used to control the priority between the `paths` option in `tsconfig.json` and the `alias` option in the bundler.

## source.alias <RsbuildDocBadge path="/config/source/alias" text="source.alias" />

Create aliases to import or require certain modules, same as the [resolve.alias](https://rspack.dev/config/resolve#resolvealias) config of Rspack.

It is important to note that `source.alias` differs from [output.externals](/config/rsbuild/output#outputexternals) in the following ways:

- The `source.alias` is used when bundling target code into the product (when [lib.bundle](/config/lib/bundle) is set to `true`). It allows you to replace the target module you want to include in the output with another module.

For example, if you want to replace `lodash` with `lodash-es` in a bundled CLI application, you can configure it as follows:

```ts title="rslib.config.ts"
export default {
// ...
source: {
alias: {
lodash: 'lodash-es',
},
},
};
```

All `lodash` modules imported in the source code will be mapped to `lodash-es` and be bundled into the output.

- `output.externals` is used to handle alias mapping for externalized modules. Externalized modules are not included in the bundle; instead, they are imported from external sources at runtime.

For example, if you want to replace `react` and `react-dom` with `preact/compat` in the bundle, you can configure it as follows:

```ts title="rslib.config.ts"
export default {
// ...
source: {
alias: {
react: 'preact/compat',
'react-dom': 'preact/compat',
},
},
};
```

Now, the code `import { useState } from 'react'` will be replaced with `import { useState } from 'preact/compat'`.

## source.assetsInclude <RsbuildDocBadge path="/config/source/assets-include" text="source.include" />

Include additional files that should be treated as static assets.
Expand Down
1 change: 1 addition & 0 deletions website/docs/zh/config/rsbuild/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
"resolve",
"source",
"output",
"tools",
Expand Down
1 change: 1 addition & 0 deletions website/docs/zh/config/rsbuild/resolve.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# resolve
Loading