Used to configure the Rspack module resolution logic.
ObjectRecord<string, false | string | (string | false)[]>{}Path alias, e.g.
{
"@": path.resolve(__dirname, './src'),
"abc$": path.resolve(__dirname, './node_modules/abc/index.js'),
}
At this point:
require("@/a") will attempt to resolve <root>/src/a.require("abc") will attempt to resolve <root>/src/abc.require("abc/file.js") will not match, and it will attempt to resolve node_modules/abc/file.js.booleantrueWhether to resolve according to the package-browser-filed-spec rule.
string[][]Same as node's conditionNames for the exports and imports fields in package.json.
string[][".js", ".json", ".wasm", ".tsx", ".ts", ".jsx"]Parse modules in order, e.g. require('. /index'), will try to parse '. /index.tsx', '. /index.jsx'...
Record<string, string[] | string>{}Define alias for the extension. e.g.
// rspack.config.js
module.exports = {
resolve: {
extensionAlias: {
'.js': ['.ts', '.js'],
},
},
};require('./index.js') will try to parse './index.ts', ./index.js.
Record<string, false | string>{}Redirect in case of failed parsing.
string[]target is ["browser", "module", "main"] when it is web["module", "main"] for othersTry to parse the fields in package.json, e.g.
// package.json
{
"name": "lib",
"module": "es/index.js"
}then import value from 'lib' results in lib/es/index.js.
string[]["index"]The filename suffix when resolving directories, e.g. require('. /dir/') will try to resolve '. /dir/index'.
string[]["exports"]Customize the exports field in package.json. e.g.
// lib/package.json
{
"name": "lib",
"testExports": {
".": "./test.js"
},
"exports": {
".": "./index.js"
}
}When this configuration is ["testExports", "exports"], the result of import value from 'lib' is lib/test.js.
string[]["node_modules"]The name of the directory to use when resolving dependencies.
booleanfalseWhen enabled, require('file') will first look for the . /file file in the current directory, not <modules>/file.
string | undefinedundefinedIf you pass the path of tsconfig.json via the option, Rspack will try to resolve modules based on the paths and baseUrl of tsconfig.json, functionally equivalent to tsconfig-paths-webpack-plugin.
const path = require('path');
/** @type {import('@rspack/cli').Configuration} */
const config = {
// ...
resolve: {
tsConfigPath: path.resolve(__dirname, 'tsconfig.json'),
},
// ...
};
module.exports = config;tsconfig.json#extends is not supported.
booleanfalseNo longer resolve extensions, no longer resolve mainFiles in package.json (but does not affect requests from mainFiles, browser, alias).
Record<string, Resolve>.Customize the Resolve configuration based on the module type.