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.
Rspack will select appropriate optimization configuration based on the mode. You can also customize the configuration via optimization.
booleantrueA module can be removed from a Chunk if the module have been included in all of its parent Chunks.
EntryChunk(index.js, a.js, b.js)
\
ChunkFoo(b.js, c.js)
/
EntryChunk2(index.js, a.js, b.js)
In the above example, b.js has already been included in EntryChunk and EntryChunk2, so b.js can be removed from ChunkFoo.
production mode.'named' | 'deterministic'| option | description |
|---|---|
named |
Use meaningful, easy-to-debug content as id. This option is enabled by default in development mode |
deterministic |
Use the hashed module identifier as the id to benefit from long-term caching. This option is enabled by default in production mode |
'named' | 'deterministic'| option | description |
|---|---|
'named' |
Readable ids for better debugging. |
'deterministic' |
Short numeric ids which will not be changing between compilation. Good for long term caching. |
deterministic as the default value in produceton mode in the next minor version.booleantrue, development mode isfalseWhether to minimize the bundle.
Array<Plugin>[]Customize the minimizer. When using a custom minimizer, the built-in minimizer will be disabled.
const minifyPlugin = require('@rspack/plugin-minify');
module.exports = {
context: __dirname,
target: 'node',
entry: {
main: './index.js',
},
optimization: {
minimize: true,
minimizer: [
new minifyPlugin({
minifier: 'terser',
}),
],
},
};booleantrueRemove empty chunks generated in the compilation.
booleantrueboolean | 'flag'true, development mode isfalse{
"name": "npm module",
"version": "1.0.0",
"sideEffects": ["**/src/*.js"]
}Tells Rspack to recognise the sideEffects flag in package.json or rules to skip over modules which are flagged to contain no side effects when exports are not used.
optimization.sideEffects dependends on builtins.treeShaking to be enabled.
This configuration has a build time cost, but eliminating modules has positive impact on performance because of less code generation. Effect of this optimization depends on your codebase.
module.exports = {
//...
optimization: {
sideEffects: true,
},
};If you only want Rspack use the manual sideEffects flag via (package.json and module.rule.sideEffects) and don't analyse code:
module.exports = {
//...
optimization: {
sideEffects: 'flag',
},
};When optimization.sideEffects is true , Rspack will also flag modules as side effect free when they contain only side effect free statements.
Adds an additional hash compilation pass after the assets have been processed to get the correct asset content hashes. This feature will enable by default in production mode.
If realContentHash is set to false, internal data is used to calculate the hash and it can change when assets are identical in some cases.
module.exports = {
//...
optimization: {
realContentHash: true,
},
};Rspack supports you to split Chunk with the optimization.splitChunks configuration item.
See details at SplitChunksPlugin.