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 generator
module.generator controls how Rspack turns parsed modules into output code or emitted assets. It affects output-related behavior such as asset filenames, public paths, CSS Modules exports, and other generation settings for each module type.
generator
- Type:
Object - Default:
{}
Use module.generator to define output generation options for each module type.
Available generator option groups:
asset,asset/inline,asset/resource: Asset generator optionscss,css/auto,css/global,css/module: CSS generator optionsjson: JSON generator options
asset
Generator options for asset modules.
asset.binary
- Type:
boolean | undefined - Default:
undefined
Whether 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.
asset.dataUrl
- Type:
Object | (source: Buffer, context: { filename: string, module: Module }) => string - Default:
{}
Only for modules with module type 'asset' or 'asset/inline'.
When used as a function, it executes for every module and must return a data URI string.
asset.dataUrl.encoding
- Type:
false | 'base64' - Default:
'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'.
asset.dataUrl.mimetype
- Type:
string - Default:
require('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'.
asset.importMode
- Type:
'url' | 'preserve' - Default:
'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':
asset.filename
- Type:
string | ((pathData: PathData, assetInfo?: AssetInfo) => string) - Default:
undefined - Supported Template string: see
output.assetModuleFilename
Same as output.assetModuleFilename. Overrides output.assetModuleFilename and only works for asset and asset/resource module types.
asset.outputPath
- Type:
string | ((pathData: PathData, assetInfo?: AssetInfo) => string) - Default:
undefined
Emit the asset in the specified folder relative to output.path.
Only for modules with module type 'asset' or 'asset/resource'.
asset.publicPath
- Type:
string | ((pathData: PathData, assetInfo?: AssetInfo) => string) - Default:
undefined
Override output.publicPath, only for modules with module type 'asset' or 'asset/resource'.
asset.emit
- Type:
boolean - Default:
true
Whether 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':
["asset/inline"]
Generator options for asset/inline modules.
["asset/inline"].binary
Same as module.generator["asset"].binary.
["asset/inline"].dataUrl
Same as module.generator["asset"].dataUrl.
["asset/inline"].dataUrl.encoding
Same as module.generator["asset"].dataUrl.encoding.
["asset/inline"].dataUrl.mimetype
Same as module.generator["asset"].dataUrl.mimetype.
["asset/resource"]
Generator options for asset/resource modules.
["asset/resource"].binary
Same as module.generator["asset"].binary.
["asset/resource"].importMode
Same as module.generator["asset"].importMode.
["asset/resource"].filename
Same as module.generator["asset"].filename.
["asset/resource"].outputPath
Same as module.generator["asset"].outputPath.
["asset/resource"].publicPath
Same as module.generator["asset"].publicPath.
["css/auto"]
Generator options for css/auto modules.
["css/auto"].exportsConvention
- Type:
'as-is' | 'camel-case' | 'camel-case-only' | 'dashes' | 'dashes-only' - Default:
'as-is'
Customize how CSS export names are exported to javascript modules, such as keeping them as is, transforming them to camel case, etc.
["css/auto"].exportsOnly
- Type:
boolean - Default:
truefor node environments,falsefor 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.
["css/auto"].localIdentName
- Type:
string - Default:
[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].
["css/auto"].localIdentHashDigest
- Type:
string - Default:
'base64url'
Configure the digest encoding used for hashes in generated CSS Modules local identifiers. This has the same supported values as output.hashDigest.
["css/auto"].localIdentHashDigestLength
- Type:
number - Default:
6
Configure how many characters from the hash are used in generated CSS Modules local identifiers.
["css/auto"].localIdentHashFunction
- Type:
string - Default:
'md4'
Configure the hash function used for generated CSS Modules local identifiers. This has the same supported values as output.hashFunction.
["css/auto"].localIdentHashSalt
- Type:
string - Default:
undefined
Configure a salt added to the hash used for generated CSS Modules local identifiers. When unset, Rspack uses output.hashSalt.
["css/auto"].esModule
- Type:
boolean - Default:
true
This 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 rules[].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:
css
Generator options for css modules.
css.exportsOnly
Same as module.generator["css/auto"].exportsOnly.
css.esModule
Same as module.generator["css/auto"].esModule.
["css/global"]
Generator options for css/global modules.
["css/global"].exportsConvention
Same as module.generator["css/auto"].exportsConvention.
["css/global"].exportsOnly
Same as module.generator["css/auto"].exportsOnly.
["css/global"].localIdentName
Same as module.generator["css/auto"].localIdentName.
["css/global"].localIdentHashDigest
Same as module.generator["css/auto"].localIdentHashDigest.
["css/global"].localIdentHashDigestLength
Same as module.generator["css/auto"].localIdentHashDigestLength.
["css/global"].localIdentHashFunction
Same as module.generator["css/auto"].localIdentHashFunction.
["css/global"].localIdentHashSalt
Same as module.generator["css/auto"].localIdentHashSalt.
["css/global"].esModule
Same as module.generator["css/auto"].esModule.
["css/module"]
Generator options for css/module modules.
["css/module"].exportsConvention
Same as module.generator["css/auto"].exportsConvention.
["css/module"].exportsOnly
Same as module.generator["css/auto"].exportsOnly.
["css/module"].localIdentName
Same as module.generator["css/auto"].localIdentName.
["css/module"].localIdentHashDigest
Same as module.generator["css/auto"].localIdentHashDigest.
["css/module"].localIdentHashDigestLength
Same as module.generator["css/auto"].localIdentHashDigestLength.
["css/module"].localIdentHashFunction
Same as module.generator["css/auto"].localIdentHashFunction.
["css/module"].localIdentHashSalt
Same as module.generator["css/auto"].localIdentHashSalt.
["css/module"].esModule
Same as module.generator["css/auto"].esModule.
json.JSONParse
- Type:
boolean - Default:
true
Use JSON.parse when the JSON string is longer than 20 characters.

