redirect
is the unique configuration for bundleless mode (set lib.bundle to false
). It will not take effect in bundle mode where all output files are packaged into a single file, eliminating the need for import path redirection.
As bundleless mode is still under development, additional redirect configurations will be introduced in the future.
Configure the redirect for import paths in output files. In bundleless mode, there are often needs such as using aliases or automatically appending suffixes for ESM products. The redirect
configuration is designed to address these issues.
Common scenarios that require redirect:
Automatically convert compilerOptions.paths
in tsconfig.json to correct relative path
For example, set compilerOptions.paths
to { "@/*": ["src/*"] }
in tsconfig.json, the output file will be redirected to the correct relative path:
Automatically append file suffix
For ESM products that run in Node.js, you must specify the exact full path for the module import to load correctly. Rslib will automatically add the suffix based on the output file.
Controls the redirect of the import paths of output JavaScript files.
When output.externals is configured and a request is matched, neither redirect.js.path
nor redirect.js.extension
will take effect, and the final rewritten request path will be entirely controlled by output.externals.
Whether to automatically redirect the import paths of JavaScript output files.
boolean
true
When set to true
, resolve.alias and resolve.aliasStrategy will take effect and applied in the rewritten import path of the output file. For TypeScript projects, you only need to configure compilerOptions.paths in the tsconfig.json file.
When set to false
, the import path will not be effected by resolve.alias, resolve.aliasStrategy and tsconfig.json.
Whether to automatically redirect the file extension to import paths based on the JavaScript output files.
boolean
true
When set to true
, the file extension will automatically be added to the rewritten import path of the output file, regardless of the original extension or whether it is specified in the import path.
When set to false
, the file extension will remain unchanged from the original import path in the rewritten import path of the output file (regardless of whether it is specified or specified as any value).
Controls the redirect of the import paths of output style files.
Whether to automatically redirect the import paths of style output files, the rules are the same as redirect.js.path.
Type: boolean
Default: true
Example:
When importing normal style files:
When importing CSS Modules files:
Whether to automatically redirect the file extension to import paths based on the style output files.
boolean
true
When set to true
, When importing a normal style file, the path will be rewritten to the .css
file. When importing CSS Modules, the path will be rewritten to the corresponding JavaScript output file.
When set to false
, The file extension will remain unchanged from the original import path.
When importing from a .less
file: