resolve
Options for module resolution.
resolve.aliasStrategy
resolve.aliasStrategy
Control the priority between the resolve.alias option and the paths option in tsconfig.json.
resolve.alias
resolve.alias
Set the alias for the module path, which is used to simplify the import path or redirect the module reference, similar to the resolve.alias config of Rspack.
For TypeScript projects, you only need to configure compilerOptions.paths in the tsconfig.json file. Rslib will automatically recognize it, so there is no need to configure the resolve.alias option separately.
It is worth noting that in bundle mode, both resolve.alias and output.externals can be used to set aliases, but they differ in the following ways:
-
resolve.aliasis used to replace the target module with another module, which will be bundled into the output.For example, if you want to replace
lodashwithlodash-eswhen bundling a package, you can configure it as follows:rslib.config.tsNow, all
lodashimports in the source code will be mapped tolodash-esand bundled into the output. -
output.externalsis 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 externalized modules
reactandreact-domwithpreact/compatin the bundle, you can configure it as follows:rslib.config.tsNow, the code
import { useState } from 'react'will be replaced withimport { useState } from 'preact/compat'.
In bundleless mode, since there is no bundling concept, all modules will be externalized. Rslib will automatically transform the modules resolved to the outBase directory based on the mappings configured in resolve.alias or compilerOptions.paths in tsconfig.json.
resolve.dedupe
resolve.dedupe
Force Rsbuild to resolve the specified packages from project root, which is useful for deduplicating packages and reducing the bundle size.
resolve.extensions
resolve.extensions
Automatically resolve file extensions when importing modules. This means you can import files without explicitly writing their extensions.
