The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.
The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.
Used to decide how to handle different types of modules in a project.
Object{}Rule[]An array of rules applied by default for modules.
See source code for details.
string | string[] | RegExp | RegExp[] | ((request: string) => boolean)undefinedKeep module mechanism of the matched modules as-is, such as module.exports, require, import.
It's useful and can boost build performance when used to ignore libraries without external dependencies.
Note: these modules will still be processed by configured loaders.
Object{}Configure all parsers' options in one place with module.parser.
Parser options for asset modules.
{ maxSize: number }{ maxSize: 8096 }If the module size is less than or equal to maxSize, then the module will be Base64 encoded, otherwise a file will be created. This option can be used only for Asset modules.
Parser options for javascript modules.
booleanfalseEnable Magic comments support for CommonJS.
Note that only webpackIgnore comment is supported at the moment:
'lazy' | 'eager' | 'weak' | 'lazy-once''lazy'Specifies global mode for dynamic import, see webpackMode for more details.
boolean | numberfalseSpecifies global prefetch for dynamic import, see webpackPrefetch for more details.
boolean | numberfalseSpecifies global preload for dynamic import, see webpackPreload for more details.
'low' | 'high' | 'auto''auto'Specifies global fetchPriority for dynamic import, see webpackFetchPriority for more details.
true | false | 'relative' | 'new-url-relative'trueEnable parsing of new URL() syntax.
true: Generate absolute URLs that include the root URL (default behavior).'relative': Generate relative URLs without the root URL.'new-url-relative': Generate static relative URLs that are replaced at compile-time with the correct public path.When using 'new-url-relative', Rspack generates relative URLs that will be replaced at compile-time with the correct public path:
When using 'relative', Rspack generates runtime code to calculate relative URLs for new URL() syntax, i.e., there's no base URL included in the result URL:
boolean | undefinedtrueEnable warnings for full dynamic dependencies (import(variable)).
boolean | undefinedfalseEnable warnings for partial dynamic dependencies (import("./path/to/" + variable)).
boolean | undefinedtrueEnable warnings when using the require function in a non-statically-analyzable way (require(variable)).
RegExp | undefined/.*/Set a regular expression to match wrapped dynamic dependencies.
booleantrueEnable or disable evaluating import.meta.
'error' | 'warn' | 'auto' | false'auto'Warn or error for using non-existent exports and conflicting re-exports.
"error": Report errors."warn": Report warnings."auto": Depending on whether the module is a strict ESM, give an error if it is, otherwise give a warning.false: Disable this feature.'error' | 'warn' | 'auto' | falseWarn or error for using non-existent exports, defaulting to the configuration of module.parser.javascript.exportsPresence.
'error' | 'warn' | 'auto' | falseWarn or error for conflicting re-exports, defaulting to the configuration of module.parser.javascript.exportsPresence.
booleanEmit errors instead of warnings when imported names don't exist in imported module.
'no-tolerant' | 'tolerant' | 'tolerant-no-check''no-tolerant'Controls error tolerance for type re-exports, commonly seen in these two scenarios:
When re-exporting types, since TypeA and TypeB are types but used in value namespace (export {}), Rspack will report warnings:
When using Rspack to bundle TypeScript, we strongly recommend enabling isolatedModules in tsconfig.json (also recommended with other bundlers as it matches how bundlers compile TypeScript: .ts files are independent and compiled separately). This will give TypeScript's own warning for type re-exports: Re-exporting a type when 'isolatedModules' is enabled requires using 'export type'.
'no-tolerant': Default behavior, shows errors for type re-exports.'tolerant': Tolerates type re-exports while verifying the existence of corresponding type exports in child modules. Requires coordination with rspackExperiments.collectTypeScriptInfo.typeExports from builtin:swc-loader to collect type export information.'tolerant-no-check': Tolerates type re-exports without checking child modules (may incorrectly tolerate some invalid cases, though IDEs usually provide warnings). Better performance as it skeps child module checks.Please refer to type reexports presence example for more details.
This is currently an experimental feature. You must enable experiments.typeReexportsPresence for this configuration to take effect.
string[] | booleanProvide custom syntax for Worker parsing, commonly used to support Worklet:
See Web Workers for more details.
'strict' | 'non-strict'Override the module to strict or non-strict.
This may affect the behavior of the module (some behaviors differ between strict and non-strict), so please configure this option carefully.
boolean | { exports?: boolean | 'skipInEsm' }trueControls CommonJS-specific parser behaviour. The default true keeps Rspack's standard handling for CommonJS export mutations. Set { exports: 'skipInEsm' } to skip rewriting CommonJS export assignments when the module is evaluated as ESM, preserving the original runtime side effects. Provide false to disable CommonJS export handling entirely.
booleanfalsePerforms cross-module inline optimization for constant exports in leaf modules of the module graph.
A common optimization case is constants.js, for example:
Inline optimization is applied when the constant value is:
null or undefinedboolean values (true or false)number with length <= 6string with length <= 6Since this feature relies on module export usage information (optimization.usedExports), it is recommended to enable it only when mode = "production".
Please refer to inline const example
This is currently an experimental feature, so you also need to enable experiments.inlineConst.
booleanfalseAllow the JavaScript parser to understand JSX syntax so that parsing and minimization can operate on files that keep JSX in the final bundle.
Enable this option when you set the loader's JSX mode to "preserve" and want to defer the actual JSX transform to a later tool (for example, libraries that ship JSX output or rely on a custom JSX runtime).
This option is experimental in Rspack and may change or be removed.
Parser options for javascript/auto modules, same as the javascript parser options.
Parser options for javascript/dynamic modules, same as the javascript parser options.
Parser options for javascript/esm modules, same as the javascript parser options.
Parser options for json modules.
numberNumber.MAX_SAFE_INTEGER, development mode is 1The depth of json dependency flagged as exportInfo.
Parser options for css/auto modules.
This configuration will only work if experiments.css is enabled.
booleantrueUse ES modules named export for CSS exports.
When using namedExports: true, you can use namespace export or named export:
When using namedExports: false, in addition to namespace export and named export, default export can also be used:
booleantrueAllow to enable/disables handling the CSS functions url.
When using url: true, Rspack will resolve the path in url function, the resolve file will be treated as an asset.
When using url: false, Rspack will ignore the path in the url function, keep the content unchanged.
Parser options for css modules.
This configuration will only work if experiments.css is enabled.
Same as module.parser["css/auto"].namedExports.
Same as module.parser["css/auto"].url.
Parser options for css/module modules.
This configuration will only work if experiments.css is enabled.
Same as module.parser["css/auto"].namedExports.
Same as module.parser["css/auto"].url.
Object{}Configure all generators' options in one place with module.generator.
Generator options for asset modules.
boolean | undefinedundefinedWhether or not this asset module should be considered binary. This can be set to false to treat this asset module as text.
If not set, the module type will be used to determine if the module is binary.
Object | (source: Buffer, context: { filename: string, module: Module }) => string{}Only for modules with module type 'asset' or 'asset/inline'.
When used a a function, it executes for every module and must return a data URI string.
false | 'base64''base64'When set to 'base64', module source will be encoded using Base64 algorithm. Setting encoding to false will disable encoding. Only for modules with module type 'asset' or 'asset/inline'.
stringrequire('mime-types').lookup(ext)A mimetype for data URI. Resolves from module resource extension by default. Only for modules with module type 'asset' or 'asset/inline'.
'url' | 'preserve''url'If "url", a URL pointing to the asset will be generated based on publicPath.
If "preserve", preserve import/require statement from generated asset.
Only for modules with module type 'asset' or 'asset/resource'.
'asset':'asset/resource':string | ((pathData: PathData, assetInfo?: AssetInfo) => string)undefinedoutput.assetModuleFilenameSame as output.assetModuleFilename. Overrides output.assetModuleFilename and only works for asset and asset/resource module types.
string | ((pathData: PathData, assetInfo?: AssetInfo) => string)undefinedEmit the asset in the specified folder relative to output.path.
Only for modules with module type 'asset' or 'asset/resource'.
string | ((pathData: PathData, assetInfo?: AssetInfo) => string)undefinedOverride output.publicPath, only for modules with module type 'asset' or 'asset/resource'.
booleantrueWhether to output assets to disk. You can set this option to false to avoid outputting unnecessary files for some scenarios such as SSR.
Only for modules with module type 'asset' or 'asset/resource'.
'asset':'asset/resource':Generator options for asset/inline modules.
Same as module.generator["asset"].binary.
Same as module.generator["asset"].dataUrl.
Same as module.generator["asset"].dataUrl.encoding.
Same as module.generator["asset"].dataUrl.mimetype.
Generator options for asset/resource modules.
Same as module.generator["asset"].binary.
Same as module.generator["asset"].importMode.
Same as module.generator["asset"].filename.
Same as module.generator["asset"].outputPath.
Same as module.generator["asset"].publicPath.
Generator options for css/auto modules.
This configuration will only work if experiments.css is enabled.
'as-is' | 'camel-case' | 'camel-case-only' | 'dashes' | 'dashes-only''as-is'Customize how CSS export names are exported to javascript modules, such as keeping them as is, transforming them to camel case, etc.
booleantrue for node environments, false for web environments.If true, only exports the identifier mappings from CSS into the output JavaScript files, without embedding any stylesheets in the template. Useful if you are using CSS Modules for pre-rendering (e.g. SSR).
If false, generate stylesheets and embed them in the template.
string[uniqueName]-[id]-[local]Customize the format of the local class names generated for CSS modules, besides the substitutions at File-level and Module-level, also include [uniqueName] and [local].
booleantrueThis configuration is available for improved ESM-CJS interoperability purposes.
Whether to add __esModule to the exports of CSS; if added, it will be treated as ES modules during ESM-CJS interop, otherwise, it will be treated as a CommonJS Module.
For example, a common use case, when using the CommonJS output from a third-party component library, it is sometimes necessary to add this configuration to ensure correct ESM-CJS interop, to obtain the correct exports (this can be used in conjunction with Rule.test and other matching conditions to add it only for that particular component library).
The original source code of the third-party component library:
The CommonJS format output published by the third-party component library:
Generator options for css modules.
This configuration will only work if experiments.css is enabled.
Same as module.generator["css/auto"].exportsOnly.
Same as module.generator["css/auto"].esModule.
Generator options for css/module modules.
This configuration will only work if experiments.css is enabled.
Same as module.generator["css/auto"].exportsConvention.
Same as module.generator["css/auto"].exportsOnly.
Same as module.generator["css/auto"].localIdentName.
Same as module.generator["css/auto"].esModule.
booleantrueUse JSON.parse when the JSON string is longer than 20 characters.
(Rule | Falsy)[][]An array of rules that match the module's requests when it is created. These rules can modify the creation behavior of the module. They can apply Loader, etc. to the module.
Rule{}Rule defines the conditions for matching a module and the behavior of handling those modules.
Rule behavior
Defines the processing behavior of the corresponding matching module, e.g. :
Rule.use)Rule.type)Rule.resolve)Defines a module's match conditions, common matches are resource, resourceQuery, include, and exclude.
Example: app.js imports ./image.png?inline#foo:
resource is /path/to/image.png, and will match against with Rule.resource ConditionresourceQuery is ?inline, and will match against with Rule.resourceQuery ConditionresourceFragment is #foo, and will match against with Rule.resourceFragment ConditionCondition represents the form of matching a given input, and it supports the following types:
String: Given an input, the match is successful when the input string satisfies startsWith. Note: You can think of it as input.startsWith(condition).RegExp: Given an input, the match is successful when the input string satisfies the regular expression. Note: You can think of it as condition.test(input).Condition[]: A list of conditions. At least one of the Conditions must match.LogicalConditions: All Conditions must match.
{ and: Condition[] }: All Conditions must match.{ or: Condition[] }: At least one of the Conditions must match.{ not: Condition }: All Conditions must NOT match.(value: string) => boolean: If it's called with the input and return a truthy value, the match is succeeds.Nested Rule can be specified under the properties Rule.rules and Rule.oneOf, These rules are evaluated only when the parent Rule condition matches. Each nested rule can contain its own conditions.
The order of evaluation is as follows:
Rule.rulesRule.oneOfConditionundefinedExcludes all modules that match this condition and will match against the absolute path of the resource (without query and fragment). This option cannot be present together with Rule.resource.
ConditionundefinedMatches all modules that match this condition against the absolute path of the resource (without query and fragment). This option cannot be present together with Rule.resource.
ConditionundefinedMatches all modules that match this resource, and will match against Resource (the absolute path without query and fragment). This option cannot be present together with Rule.test.
ConditionundefinedMatches all modules that match this resource against the Resource's query. Note: Containing ?, when Rule.resourceQuery is ?raw, it will match the resource request of foo?raw
ConditionundefinedMatches all modules that match this resource against the Resource's fragment. Note: Containing #, when Rule.resourceFragment is #abc, it will match the resource request of foo#abc
ConditionundefinedMatches all modules that match this resource, and will match against Resource (the absolute path without query and fragment). This option cannot be present together with Rule.resource.
ConditionundefinedMatches all modules that match this resource, and will match against Resource (the absolute path without query and fragment) of the module that issued the current module.
stringundefinedMatches all modules that match this resource, and will match against layer of the module that issued the current module.
For version before v1.6.0, this configuration will only work if experiments.layers = true.
A basic example:
A more complex example is the combination with entry options to build modern and legacy bundles at the same time:
ConditionundefinedMatches all modules that match this resource, and will match against the category of the dependency that introduced the current module, for example:
esm for import and import()cjs for require()url for new URL() and url().For example, match all .js files, but exclude url type dependencies (such as new URL('./path/to/foo.js', import.meta.url)):
ConditionundefinedMatches all modules that match this resource, and will match against the Resource's scheme.
For example, you can treat the inline data uri resource as a separate resource with the following configuration:
ConditionundefinedMatches modules based on MIME type instead of file extension. It's primarily useful for data URI module.
{ [key: string]: Condition }undefineddescriptionData option allows you to match values of properties in the description file, typically package.json, to determine which modules a rule should apply to. This is a useful way to apply rules to specific modules based on metadata found in their package.json.
The object keys in descriptionData correspond to keys in the module's package.json, such as name, version, etc. Each key should be associated with a Condition for matching the package.json data.
For example, below we are applying the rule only to JavaScript resources with 'rspack' string included in their package.json name.
{ [key: string]: Condition }undefinedwith can be used in conjunction with import attributes.
For example, the following configuration will match { type: "url" } and will change the type of the matched modules to "asset/resource":
The following import will match:
It should be noted that in order for Rspack to properly match the with syntax, when you use builtin:swc-loader, you need to manually enable the keepImportAttributes configuration to preserve import attributes:
This option is deprecated, please use Rule.use instead
Rule.loader is a shortcut to Rule.use: [ { loader } ]. See Rule.use for details.
Rule.options is a shortcut to Rule.use: [ { options } ]. See Rule.use for details.
Object{}Parser options for the specific modules that matched by the rule conditions, this will override the parser options in module.parser.
For specific parser options and the corresponding module type, you can refer to module.parser.
Object{}Generator options for the specific modules that matched by the rule conditions, this will override the parser options in module.generator.
For specific generator options and the corresponding module type, you can refer to module.generator.
booleanFlag the module for side effects, this will affect the result of Tree Shaking.
'pre' | 'post'Specifies the category of the loader. When not specified, it defaults to normal loader.
There is also an additional category "inlined loader" which are loaders applied inline of the import/require.
When specified as 'pre', the loader will execute before all other loaders.
When specified as 'post', the loader will execute after all other loaders.
There are two phases that all loaders enter one after the other:
pitch method on loaders is called in the order post, inline, normal, pre. See Pitching Loader for details.pre, normal, inline, post. Transformation on the source code of a module happens in this phase.Used to mark the type of the matching module, which affects how the module is handled by Rspack's built-in processing.
By default, Rspack will determine the type of the module based on the file extension. For example:
.js files will be treated as javascript/auto modules..mjs files, as well as .js files in packages with type="module" in package.json, will be treated as javascript/esm modules..json files will be treated as json modules..css files will be treated as css/auto modules.For example, if you want to load a .json file through a custom loader, you'd need to set the type to javascript/auto to bypass Rspack's built-in JSON importing.
The meanings of all type options are as follows:
'javascript/auto': JavaScript modules. Rspack automatically determines the module type based on file content, providing the best compatibility.'javascript/esm': JavaScript modules, treated as strict ES modules.'javascript/dynamic': JavaScript modules, treated as Script.'json': JSON data module, see JSON.'css' | 'css/module' | 'css/auto': CSS module, see Built-in CSS support.'asset' | 'asset/source' | 'asset/resource' | 'asset/inline': Asset module, see Asset Module.stringUsed to mark the layer of the matching module. A group of modules could be united in one layer which could then be used in split chunks, stats or entry options.
For version before v1.6.0, this configuration will only work if experiments.layers = true.
An array to pass the Loader package name and its options. string[] e.g.: use: ['svgr-loader'] is shorthand for use: [ { loader: 'svgr-loader' } ].
Loaders will be executed in right-to-left order.
A function can also be used:
booleanfalseIn version 1.3.1, the Rule.use.parallel configuration option was introduced. When enabled for corresponding loaders and experiments.parallelLoader = true is configured, the respective loaders will be executed in worker threads:
When multiple loaders in the current Rule are configured with Rule.use.parallel = true, Rspack will execute all loader tasks in the same worker until it encounters the next loader without the parallel flag or a Rust builtin: loader. This approach enhances loader parallel performance.
LoaderContext._compilation, LoaderContext._compiler, LoaderContext._module.Set specific module resolve options based on the matching modules.
Rule[]undefinedA kind of Nested Rule, an array of Rules that is also used when the parent Rule matches.
(Rule | Falsy)[]undefinedA kind of Nested Rule, an array of Rules from which only the first matching Rule is used when the parent Rule matches.
booleanfalseExtracts existing source map data from files (from their //# sourceMappingURL comment), useful for preserving the source maps of third-party libraries.