Closed xc2 closed 1 day ago
Related to output: node
. The related code is https://github.com/web-infra-dev/rsbuild/blob/main/packages/core/src/plugins/splitChunks.ts#L224 which directly return. It's documented here
When the Rsbuild target is "node", since Node Bundles do not need to be split to optimize loading performance, the chunkSplit rule will not take effect.
This makes sense, but it also prevents splitting chunks by config.performance.chunkSplit
and can use tools.rspack.optimization.splitChunks
only. I think maybe strategy: "costom"
could be applied to the node or webworker type? cc @chenjiahan
Yes we should allow to manually configuring split chunks for the node target, let me think about how to allow it..
For the node target, I think only splitting async chunks is allowed. If we split some initial chunks, HTML plugin can reload all of them, but Node package consumers can only import an entry module rather than import all initial modules.
For the web worker target, as far as I know, only importScripts
is allowed to import other scripts, so chunk splitting never seems to work in the worker thread.
I have added documentation the clarify the current behavior: https://github.com/web-infra-dev/rsbuild/pull/4088
This means that when output.target
is node
or web-worker
, Rsbuild's performance.chunkSplit
will not take effect. If we change this default behavior, this may have unpredictable impacts on existing SSR projects.
Using tools.rspack
should work if users need to split Node bundles:
export default {
tools: {
rspack: {
optimization: {
splitChunks: {
// options
},
},
},
},
};
Version
Details
rslib config
rslib.config.ts
```ts import { defineConfig } from "@rslib/core"; export default defineConfig({ output: { cleanDistPath: true }, lib: [ { format: "cjs", syntax: "es2021", dts: false, autoExternal: false, autoExtension: false, source: { entry: { bun: "./binary/bun.ts", node: "./binary/node.ts", }, }, performance: { chunkSplit: { strategy: "custom", splitChunks: { cacheGroups: { sources: { test: /./, name: "sources", enforce: true, chunks: "all", reuseExistingChunk: true, }, }, }, }, }, output: { externals: { url: "node:url", buffer: "node:buffer", events: "node:events", }, minify: true, cleanDistPath: false, target: "node", distPath: { root: "releases/binary", jsAsync: "internal", }, }, }, ], }); ```Inspect
Only
chunks: 'async'
is in rspack configReproduce link
-
Reproduce Steps
-