You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/en/config/rsbuild/resolve.mdx
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,9 @@ Control the priority between the `paths` option in `tsconfig.json` and the `reso
12
12
13
13
Create aliases to import or require certain modules, same as the [resolve.alias](https://rspack.dev/config/resolve#resolvealias) config of Rspack.
14
14
15
-
It is important to note that `resolve.alias`differs from [output.externals](/config/rsbuild/output#outputexternals) in the following ways:
15
+
It is worth noting that in bundle mode, both `resolve.alias`and [output.externals](/config/rsbuild/output#outputexternals) can be used to set aliases, but they differ in the following ways:
16
16
17
-
-`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`.
17
+
-`resolve.alias`is used to replace the target module with another module, which will be bundled into the output.
18
18
19
19
For example, if you want to replace `lodash` with `lodash-es` when bundling a package, you can configure it as follows:
20
20
@@ -29,11 +29,11 @@ It is important to note that `resolve.alias` differs from [output.externals](/co
29
29
};
30
30
```
31
31
32
-
All `lodash`modules imported in the source code will be mapped to `lodash-es` and be bundled into the output.
32
+
Now, all `lodash`imports in the source code will be mapped to `lodash-es` and bundled into the output.
33
33
34
34
-`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.
35
35
36
-
For example, if you want to replace `react` and `react-dom` with `preact/compat` in the bundle, you can configure it as follows:
36
+
For example, if you want to replace externalized modules `react` and `react-dom` with `preact/compat` in the bundle, you can configure it as follows:
37
37
38
38
```ts title="rslib.config.ts"
39
39
exportdefault {
@@ -49,6 +49,10 @@ It is important to note that `resolve.alias` differs from [output.externals](/co
49
49
50
50
Now, the code `import { useState } from 'react'` will be replaced with `import { useState } from 'preact/compat'`.
51
51
52
+
::: note
53
+
In bundleless mode, since there is no bundling concept, all modules will be externalized, so Rslib will automatically externalize the aliased module in the final output by using `output.externals`.
0 commit comments