website/docs/en/plugins/runtime-chunk-plugin.mdx
RuntimeChunkPlugin creates separate runtime chunks and controls how they are named. optimization.runtimeChunk applies this plugin internally.
This configuration extracts the runtime used by two entry points into runtime.js:
import { rspack } from '@rspack/core';
export default {
entry: {
app: './src/app.js',
admin: './src/admin.js',
},
output: {
filename: '[name].js',
},
plugins: [
new rspack.optimize.RuntimeChunkPlugin({
name: 'runtime',
}),
],
};
Rspack emits app.js, admin.js, and the shared runtime.js. Keeping the runtime separate allows entry bundles to be cached independently from runtime changes.
Used to configure the name of the runtime chunk; it can be a string or a function that returns a string, where the function parameter is the name of the entry.
string | ((entrypoint: { name: string }) => string)new rspack.optimize.RuntimeChunkPlugin({
name: ({ name }) => `runtime~${name}`,
});