模块解析:该选项用于配置 Rspack 模块解析逻辑。
ObjectRecord<string, false | string | (string | false)[]>{}路径别名,例如:
此时:
require("@/a") 会尝试解析 <root>/src/a。require("abc") 会尝试解析 <root>/src/abc。require("abc/file.js") 不会命中匹配规则,它会尝试去解析 node_modules/abc/files.js。string[]['browser']定义一个字段,例如 browser,以依照此规范进行解析。
booleantrue是否按照 package-browser-filed-spec 规则解析。
等同于 enhanced-resolve 的 resolve.aliasFields = ["browser"]。
string[][]与 node 的 conditionNames 相同,用于 package.json 中的 exports 和 imports 字段。
string[][".js", ".json", ".wasm"]按照顺序解析模块,例如 require('./index'),会依次尝试解析 './index.js'、'./index.json'...
Record<string, string[] | string>{}定义拓展名的别名,例如
在 require('./index.js') 时,会依次尝试解析 './index.ts', ./index.js。
Record<string, false | string>{}解析失败时的重定向。
string[]target 为 web 时为 ["browser", "module", "main"]["module", "main"]尝试解析 package.json 中的字段,例如:
则 import value from 'lib' 的结果为 lib/es/index.js。
string[]["index"]解析目录时的文件名后缀,例如 require('./dir/') 会尝试解析 './dir/index'。
string[]["exports"]自定义 package.json 中的 exports 字段,例如:
则当配置为 ["testExports", "exports"] 时, import value from 'lib' 的结果为 lib/test.js。
string[]["node_modules"]解析依赖时的目录名。
booleanfalse当开启时,require('file') 会首先寻找当前目录下的 ./file 文件,而不是 <modules>/file。
booleanfalse在解析时,倾向使用与 resolve.roots 相关的绝对路径。
string | undefinedundefined这个选项接受的是 tsconfig.json 的文件路径。在开启这个选项后, Rspack 会基于 tsconfig.json 中 的 paths 和 baseUrl 来寻找模块,其功能等同于 tsconfig-paths-webpack-plugin。
不支持 tsconfig.json#extends 字段。
objectundefinedstring这个选项接受的是 tsconfig.json 的文件路径。在开启这个选项后, Rspack 会基于 tsconfig.json 中 的 paths 和 baseUrl 来寻找模块,其功能等同于 tsconfig-paths-webpack-plugin。
string[] | "auto" | undefinedundefined支持 tsconfig-paths-webpack-plugin 中定义的 tsconfig project references.
可以通过文件路径用于手动配置,或者使用 auto 用于自动读取 tsconfig.references 中的文件路径。
使用 undefined 将会关闭该功能。
booleanfalse不再解析扩展名,不再解析 package.json 中的 mainFiles(但不会影响来自 mainFiles, browser, alias 的请求)。
string[][]限制请求解析路径的解析限制列表。
string[][]一个目录列表,用于解析服务器相对 URL(以'/'开头的 URL)。默认使用 context 配置选项。在非 Windows 系统上,这些请求首先作为绝对路径进行解析。
Record<string, Resolve>.依据模块类型自定义 Resolve 配置。