Interface: Resolve
The Resolve option is used to control the resolution behavior of Rspack.
Properties
alias?
optionalalias?:Record<string,string|false|string[]>
Create aliases to import or require certain modules more easily.
Default Value
Examples
A trailing $ can also be added to the given object's keys to signify an exact match:
which would yield these results:
resolve.alias is useful to control how a npm package is resolved.
- Change
reactto@lynx-js/react:
This allows you to use some third-party libraries that directly uses react as dependencies in ReactLynx.
- Force using the same version of
dayjs:
Please note that this is dangerous, since all the dayjs(including the dependencies of a dependencies) is resolved to the version in the project.
It may cause both compile-time and runtime errors due to version mismatch.
Setting resolve.alias to false will ignore a module.
aliasStrategy?
optionalaliasStrategy?:"prefer-tsconfig"|"prefer-alias"
Set the strategy for path alias resolution, to control the priority relationship
between the paths option in tsconfig.json and the resolve.alias option of Rsbuild.
Default Value
'prefer-tsconfig'
Remarks
prefer-tsconfig(default): Thepathsoption intsconfig.jsonwill take precedence over theresolve.aliasoption of Rsbuild.prefer-alias: Theresolve.aliasoption of Rsbuild will take precedence over thepathsoption intsconfig.json.
Example
dedupe?
optionaldedupe?:string[]
Force to resolve the specified packages from project root, which is useful for deduplicating packages and reducing the bundle size.
Default Value
Remarks
Resolve.dedupe is implemented based on Resolve.alias, it will get the path of the specified package through require.resolve in the project root directory and set it to the alias.
The alias generated by Resolve.dedupe will be merged with the configured Resolve.alias in the project, and the Resolve.alias config will take precedence when the keys are the same.
Example
Use tslib from the project root directory.
extensions?
optionalextensions?:string[]
Lynx Default Changed
Automatically resolve file extensions when importing modules. This means you can import files without explicitly writing their extensions.
Default Value
['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json', '.cjs']
Remarks
For example, if importing './index', Rsbuild will try to resolve using the following order:
-
./index.ts -
./index.tsx -
./index.mjs -
./index.js -
./index.jsx -
./index.json -
./index.cjs
The difference between resolve.extensions and tools.rspack.resolve.extensions:
resolve.extensions: Replaces the default list; pluginLynx still appends .cjs.
tools.rspack.resolve.extensions: Merges with the default configuration using webpack-merge.