Skip to content

Commit 8093f73

Browse files
authored
docs: add resolve field of Rsbuild config (#517)
1 parent 1bdbf5a commit 8093f73

File tree

6 files changed

+56
-46
lines changed

6 files changed

+56
-46
lines changed

website/docs/en/config/rsbuild/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
"resolve",
23
"source",
34
"output",
45
"tools",

website/docs/en/config/rsbuild/output.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Whether to emit CSS to the output bundles.
4444

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

47-
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.
47+
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.
4848

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
2+
3+
# resolve
4+
5+
## resolve.aliasStrategy <RsbuildDocBadge path="/config/resolve/alias-strategy" text="resolve.aliasStrategy" />
6+
7+
`resolve.aliasStrategy` is used to control the priority between the `paths` option in `tsconfig.json` and the `alias` option in the bundler.
8+
9+
## resolve.alias <RsbuildDocBadge path="/config/resolve/alias" text="resolve.alias" />
10+
11+
Create aliases to import or require certain modules, same as the [resolve.alias](https://rspack.dev/config/resolve#resolvealias) config of Rspack.
12+
13+
It is important to note that `resolve.alias` differs from [output.externals](/config/rsbuild/output#outputexternals) in the following ways:
14+
15+
- `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`.
16+
17+
For example, if you want to replace `lodash` with `lodash-es` in a bundled CLI application, you can configure it as follows:
18+
19+
```ts title="rslib.config.ts"
20+
export default {
21+
// ...
22+
resolve: {
23+
alias: {
24+
lodash: 'lodash-es',
25+
},
26+
},
27+
};
28+
```
29+
30+
All `lodash` modules imported in the source code will be mapped to `lodash-es` and be bundled into the output.
31+
32+
- `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.
33+
34+
For example, if you want to replace `react` and `react-dom` with `preact/compat` in the bundle, you can configure it as follows:
35+
36+
```ts title="rslib.config.ts"
37+
export default {
38+
// ...
39+
output: {
40+
externals: {
41+
react: 'preact/compat',
42+
'react-dom': 'preact/compat',
43+
},
44+
},
45+
};
46+
```
47+
48+
Now, the code `import { useState } from 'react'` will be replaced with `import { useState } from 'preact/compat'`.
49+
50+
## resolve.dedupe <RsbuildDocBadge path="/config/resolve/dedupe" text="resolve.dedupe" />
51+
52+
`resolve.dedupe` is used to resolve the specified packages from project root, which is useful for deduplicating packages and reducing the bundle size.

website/docs/en/config/rsbuild/source.mdx

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,6 @@ import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
55

66
Configure the source code parsing and compilation options.
77

8-
## source.aliasStrategy <RsbuildDocBadge path="/config/source/alias-strategy" text="source.aliasStrategy" />
9-
10-
`source.aliasStrategy` is used to control the priority between the `paths` option in `tsconfig.json` and the `alias` option in the bundler.
11-
12-
## source.alias <RsbuildDocBadge path="/config/source/alias" text="source.alias" />
13-
14-
Create aliases to import or require certain modules, same as the [resolve.alias](https://rspack.dev/config/resolve#resolvealias) config of Rspack.
15-
16-
It is important to note that `source.alias` differs from [output.externals](/config/rsbuild/output#outputexternals) in the following ways:
17-
18-
- 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.
19-
20-
For example, if you want to replace `lodash` with `lodash-es` in a bundled CLI application, you can configure it as follows:
21-
22-
```ts title="rslib.config.ts"
23-
export default {
24-
// ...
25-
source: {
26-
alias: {
27-
lodash: 'lodash-es',
28-
},
29-
},
30-
};
31-
```
32-
33-
All `lodash` modules imported in the source code will be mapped to `lodash-es` and be bundled into the output.
34-
35-
- `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.
36-
37-
For example, if you want to replace `react` and `react-dom` with `preact/compat` in the bundle, you can configure it as follows:
38-
39-
```ts title="rslib.config.ts"
40-
export default {
41-
// ...
42-
source: {
43-
alias: {
44-
react: 'preact/compat',
45-
'react-dom': 'preact/compat',
46-
},
47-
},
48-
};
49-
```
50-
51-
Now, the code `import { useState } from 'react'` will be replaced with `import { useState } from 'preact/compat'`.
52-
538
## source.assetsInclude <RsbuildDocBadge path="/config/source/assets-include" text="source.include" />
549

5510
Include additional files that should be treated as static assets.

website/docs/zh/config/rsbuild/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
"resolve",
23
"source",
34
"output",
45
"tools",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# resolve

0 commit comments

Comments
 (0)