CC 4.0 License
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.
Module parser
module.parser controls how Rspack reads modules after they are resolved. It affects how dependencies are collected, how syntax such as import.meta and dynamic import() is interpreted, and other parsing behavior for each module type.
parser
- Type:
Object - Default:
{}
Use module.parser to define parser options for each module type.
Available parser option groups:
asset: Asset parser optionsjavascript,javascript/auto,javascript/dynamic,javascript/esm: JavaScript parser optionsjson: JSON parser optionscss,css/auto,css/global,css/module: CSS parser options
asset
Parser options for asset modules.
asset.dataUrlCondition
- Type:
{ maxSize: number } - Default:
{ 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.
javascript
Parser options for javascript modules.
javascript.commonjsMagicComments
- Type:
boolean - Default:
false
Enable Magic comments support for CommonJS.
Note that only webpackIgnore comment is supported at the moment:
javascript.dynamicImportMode
- Type:
'lazy' | 'eager' | 'weak' | 'lazy-once' - Default:
'lazy'
Specifies global mode for dynamic import, see webpackMode for more details.
javascript.dynamicImportPrefetch
- Type:
boolean | number - Default:
false
Specifies global prefetch for dynamic import, see webpackPrefetch for more details.
javascript.dynamicImportPreload
- Type:
boolean | number - Default:
false
Specifies global preload for dynamic import, see webpackPreload for more details.
javascript.dynamicImportFetchPriority
- Type:
'low' | 'high' | 'auto' - Default:
'auto'
Specifies global fetchPriority for dynamic import, see webpackFetchPriority for more details.
javascript.url
- Type:
true | false | 'relative' | 'new-url-relative' - Default:
true
Enable 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:
javascript.exprContextCritical
- Type:
boolean | undefined - Default:
true
Enable warnings for full dynamic dependencies (import(variable)).
javascript.wrappedContextCritical
- Type:
boolean | undefined - Default:
false
Enable warnings for partial dynamic dependencies (import("./path/to/" + variable)).
javascript.unknownContextCritical
- Type:
boolean | undefined - Default:
true
Enable warnings when using the require function in a non-statically-analyzable way (require(variable)).
javascript.wrappedContextRegExp
- Type:
RegExp | undefined - Default:
/.*/
Set a regular expression to match wrapped dynamic dependencies.
javascript.importMeta
- Type:
boolean | 'preserve-unknown' - Default: When using ESM output, the default value is
'preserve-unknown'; otherwise, it istrue
Control whether Rspack parses and replaces import.meta in source code. Available values:
"preserve-unknown": Knownimport.metaproperties are statically analyzed at compile-time, other properties are preserved and evaluated at runtime.true: Allimport.metaproperties are statically analyzed at compile-time.false: Allimport.metaproperties are evaluated at runtime.
javascript.exportsPresence
- Type:
'error' | 'warn' | 'auto' | false - Default:
'error'
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.
javascript.importExportsPresence
- Type:
'error' | 'warn' | 'auto' | false
Warn or error for using non-existent exports, defaulting to the configuration of module.parser.javascript.exportsPresence.
javascript.reexportExportsPresence
- Type:
'error' | 'warn' | 'auto' | false
Warn or error for conflicting re-exports, defaulting to the configuration of module.parser.javascript.exportsPresence.
javascript.typeReexportsPresence
- Type:
'no-tolerant' | 'tolerant' | 'tolerant-no-check' - Default:
'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 withcollectTypeScriptInfo.typeExportsfrom 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.
javascript.worker
- Type:
string[] | boolean
Provide custom syntax for Worker parsing, commonly used to support Worklet:
See Web Workers for more details.
javascript.overrideStrict
- Type:
'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.
javascript.commonjs
- Type:
boolean | { exports?: boolean | 'skipInEsm' } - Default:
true
Controls 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.
javascript.requireAlias
- Type:
boolean - Default:
false
Control whether renaming of the CommonJS require function will be parsed and transformed.
When set to true, Rspack will parse and transform cases where require is assigned to a variable or passed as a parameter (e.g., const req = require; req('./module')).
javascript.requireAsExpression
- Type:
boolean - Default:
true
Control whether require used as an expression will be parsed.
When set to true, Rspack will parse require when it's used as an expression (e.g., const req = require; req('./module')) and emit a warning. When set to false, this pattern will be ignored.
javascript.requireDynamic
- Type:
boolean - Default:
true
Control whether dynamic require calls will be parsed.
When set to false, Rspack will not parse dynamic require calls where the module path is not a static string (e.g., require(variable)). This can improve build performance if your code doesn't use dynamic requires.
javascript.requireResolve
- Type:
boolean - Default:
true
Control whether require.resolve() calls will be parsed.
When set to false, Rspack will not parse require.resolve() calls. This can improve build performance if your code doesn't use require.resolve().
javascript.importDynamic
- Type:
boolean - Default:
true
Control whether dynamic import() calls will be parsed.
When set to false, Rspack will not parse dynamic import() calls where the module path is not a static string (e.g., import(variable)). This can improve build performance if your code doesn't use dynamic imports.
javascript.strictThisContextOnImports
- Type:
boolean - Default:
false
Controls whether Rspack preserves the this binding strictly when calling exported functions as object members from imported modules.
This mainly affects cases where an exported function uses this to refer to the current module object, for example:
In the example above, enabling this option prints 42. When it is disabled, value is considered unused and removed for better tree shaking, so the result becomes undefined.
- When set to
true, Rspack follows the spec more strictly and prioritizes correct runtimethissemantics, but tree shaking can become less effective. - When set to
false, Rspack can generate more optimized output, but runtimethissemantics may no longer be preserved in these patterns.
This pattern is uncommon in real-world ESM code, and enabling the option can reduce tree shaking effectiveness, so the default is false.
If you run into this pattern in practice, it is usually better to avoid relying on it. If that is not possible, prefer enabling it only for specific modules with module rule condition.
javascript.jsx
- Type:
boolean - Default:
false
Allow 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.
javascript.importMetaResolve
- Type:
boolean - Default:
false
Allow the JavaScript parser to understand import.meta.resolve() syntax.
Currently, import.meta.resolve("./module") behaves similarly to require.resolve("./module"): it includes the module in the final bundle and returns the module ID.
This option is experimental in Rspack and may change or be removed.
javascript.pureFunctions
- Type:
string[]
Manually mark top-level identifiers in matched modules as side-effect-free for pure-function-based tree shaking. Each name must resolve to a supported top-level name in the module — a function/class/variable declaration, an import specifier, an exported alias such as export { foo as bar }, or default for a default-exported function or arrow.
This option is mainly intended for third-party libraries whose source cannot be annotated directly. You can either configure it on the library file itself, or on a consumer file to assert that calls to a particular import are pure.
Although the option lives under module.parser.javascript, in practice it is usually better to apply it through module.rules[i].parser so you can configure pureFunctions more precisely for specific modules.
This option only takes effect when experiments.pureFunctions is enabled, and Rspack emits a warning if a configured name does not appear as a top-level binding in the matched module.
["javascript/auto"]
Parser options for javascript/auto modules, same as the javascript parser options.
["javascript/dynamic"]
Parser options for javascript/dynamic modules, same as the javascript parser options.
["javascript/esm"]
Parser options for javascript/esm modules, same as the javascript parser options.
json
Parser options for json modules.
json.exportsDepth
- Type:
number - Default: production mode is
Number.MAX_SAFE_INTEGER, development mode is1
The depth of json dependency flagged as exportInfo.
["css/auto"]
Parser options for css/auto modules.
["css/auto"].namedExports
- Type:
boolean - Default:
true
Use 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:
["css/auto"].url
- Type:
boolean - Default:
true
Allow 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.
["css/auto"].resolveImport
- Type:
boolean | ((context: { url: string, media: string | undefined, resourcePath: string, supports: string | undefined, layer: string | undefined }) => boolean) - Default:
true
Whether to resolve @import syntax.
true: enable processing of@importrules (default).false: disable processing of@importrules.function: only process@importrules that satisfy the condition.
["css/auto"].import
- Type:
boolean - Default:
true
Whether to handle CSS @import at-rules.
true: resolve and process@importrules (default).false: leave@importrules unchanged in the generated CSS.
["css/auto"].animation
- Type:
boolean - Default:
true
Enable or disable renaming local @keyframes identifiers and their animation or animation-name usages.
["css/auto"].customIdents
- Type:
boolean - Default:
false
Enable or disable renaming custom identifiers, such as local @counter-style and @font-palette-values names.
["css/auto"].dashedIdents
- Type:
boolean - Default:
false
Enable or disable renaming dashed identifiers, such as CSS custom properties and @property declarations.
css
Parser options for css modules.
css.namedExports
Same as module.parser["css/auto"].namedExports.
css.url
Same as module.parser["css/auto"].url.
css.resolveImport
Same as module.parser["css/auto"].resolveImport.
css.import
Same as module.parser["css/auto"].import.
css.animation
Same as module.parser["css/auto"].animation.
css.customIdents
Same as module.parser["css/auto"].customIdents.
css.dashedIdents
Same as module.parser["css/auto"].dashedIdents.
["css/global"]
Parser options for css/global modules.
["css/global"].namedExports
Same as module.parser["css/auto"].namedExports.
["css/global"].url
Same as module.parser["css/auto"].url.
["css/global"].resolveImport
Same as module.parser["css/auto"].resolveImport.
["css/global"].import
Same as module.parser["css/auto"].import.
["css/global"].animation
Same as module.parser["css/auto"].animation.
["css/global"].customIdents
Same as module.parser["css/auto"].customIdents.
["css/global"].dashedIdents
Same as module.parser["css/auto"].dashedIdents.
["css/module"]
Parser options for css/module modules.
["css/module"].namedExports
Same as module.parser["css/auto"].namedExports.
["css/module"].url
Same as module.parser["css/auto"].url.
["css/module"].resolveImport
Same as module.parser["css/auto"].resolveImport.
["css/module"].import
Same as module.parser["css/auto"].import.
["css/module"].animation
Same as module.parser["css/auto"].animation.
["css/module"].customIdents
Same as module.parser["css/auto"].customIdents.
["css/module"].dashedIdents
Same as module.parser["css/auto"].dashedIdents.

