You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/en/config/output.mdx
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,18 @@ The name of the file to be output by the Asset module. This value can be overrid
33
33
-**Type:**`boolean`
34
34
-**Default:**`true`
35
35
36
-
Create async chunks that are loaded on demand.
36
+
Controls whether dynamically imported modules are emitted as separate async chunks or bundled into existing chunks.
37
+
38
+
-`true`: Modules loaded via `import()` are split into independent async chunks. These chunks are emitted as separate files and are loaded on demand at runtime. This enables code splitting and keeps the initial bundle smaller.
39
+
-`false`: Dynamically imported modules are bundled into existing chunks instead of being emitted as separate files. No additional async chunk files are generated.
Copy file name to clipboardExpand all lines: website/docs/en/guide/optimization/code-splitting.mdx
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,11 +32,11 @@ console.log('bar.js');
32
32
Building this project produces three chunks: `src_bar_js.js`, `src_foo_js.js`, and `main.js`. Inspecting them shows that `shared.js` exists in both `src_bar_js.js` and `src_foo_js.js`. We will cover how to remove duplicated modules later.
33
33
34
34
:::tip
35
-
Refer to [Module methods - Dynamic import()](/api/runtime-api/module-methods#dynamic-import) for the detailed dynamic import API, as well as how to use dynamic expressions and magic comments in dynamic import.
36
-
:::
37
35
38
-
:::info
39
-
Although `shared.js` exists in two chunks, it is executed only once, so you don't have to worry about multiple instances.
36
+
1. Refer to [Module methods - Dynamic import()](/api/runtime-api/module-methods#dynamic-import) for the detailed dynamic import API, as well as how to use dynamic expressions and magic comments in dynamic import.
37
+
2. Although `shared.js` exists in two chunks, it is executed only once, so you don't have to worry about multiple instances.
38
+
3. Use the [output.asyncChunks option](/config/output/#outputasyncchunks) to control whether dynamically imported modules generate independent async chunks.
39
+
40
40
:::
41
41
42
42
## Entry point
@@ -79,13 +79,13 @@ Entrypoint index = index.js
79
79
80
80
Similarly, examining the output shows that they all include the repeated `shared.js`.
81
81
82
-
## SplitChunksPlugin
82
+
## Configuring chunk splitting
83
83
84
84
The splitting approach above is intuitive, but most modern browsers support concurrent network requests. If we split a single-page application into one chunk per page, the browser still has to fetch a large chunk when users switch pages, which wastes that concurrency. Instead, we can break the chunk into smaller ones and request those smaller chunks at the same time to use the browser's network capacity more effectively.
85
85
86
86
Rspack defaults to splitting files in the `node_modules` directory and duplicate modules, extracting these modules from their original Chunk into a separate new Chunk. Why does `shared.js` still appear repeatedly in our example above? The `shared.js` file here is very small, and splitting such a small module into its own Chunk can actually slow down loading.
87
87
88
-
We can configure the minimum split size to 0 to allow `shared.js` to be extracted on its own.
88
+
We can configure the minimum split size through [splitChunks.minSize](/plugins/webpack/split-chunks-plugin#splitchunksminsize)to 0 to allow `shared.js` to be extracted on its own.
89
89
90
90
```diff title="rspack.config.mjs"
91
91
export default {
@@ -104,7 +104,7 @@ After rebuilding, you will find that `shared.js` has been extracted separately,
104
104
105
105
### Force the splitting of certain modules
106
106
107
-
We can specify certain modules to be forcibly grouped into a single Chunk, for example, the following configuration:
107
+
We can use [`optimization.splitChunks.cacheGroups.{cacheGroup}.name`](/plugins/webpack/split-chunks-plugin#splitchunkscachegroupscachegroupname) to force specific modules to be grouped into the same chunk, for example, with the following configuration:
0 commit comments