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/experiments.mdx
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -959,3 +959,37 @@ export default {
959
959
},
960
960
};
961
961
```
962
+
963
+
## experiments.lazyBarrel
964
+
965
+
<ApiMeta addedVersion="1.5.0" />
966
+
967
+
- **Type:** `boolean`
968
+
- **Default:** `false`
969
+
970
+
Whether to skip building unused re-export modules in side-effect-free barrel files to optimize build performance.
971
+
972
+
A side-effect-free module is a module that meets one of the following conditions:
973
+
974
+
- The `package.json` file of its package declares `"sideEffects":false`, see [Side effects analysis](/guide/optimization/tree-shaking#side-effects-analysis)
975
+
- Modules explicitly marked as `false` through the [module.rule.sideEffects](/config/optimization#optimizationsideeffects) option
976
+
977
+
:::info FAQ
978
+
979
+
1. Can this also supports CommonJS?
980
+
981
+
Yes, theoretically this can also support CommonJS, but before that we need to improve Rspack's CJS tree shaking first, the static analyze part specifically, so currently we will only support ESM, and support CJS in the future PR.
982
+
983
+
2. Why depend on `"sideEffects":false` in package.json, can Rspack automatically analyze a module is side effects free or not?
984
+
985
+
Rspack has the ability to analyze a module is side effects free or not of course, it's already used by `optimization.sideEffects` to tree shaking side effects free modules. But these analyzed modules still require checking whether their dependencies have side effects - only when all dependencies are also side effects free can the module be considered truly side effects free. However, during the make phase, dependencies must first be built before their side effects can be analyzed, and the `lazyBarrel` is intend to avoid to build those dependencies. `"sideEffects":false` in package.json or `module.rule.sideEffects` doesn't require dependency checking, as it signifies the entire package is side effects free. Therefore, `lazyBarrel` can only rely on this marker rather than automatic analysis.
986
+
987
+
3. So `export*from"./x"` is not a problem any more?
988
+
989
+
No, `export*from"./x"` is still a bad practice for your build performance, `lazyBarrel` won't build the star re-export only when you import a specifier, and the side effects free barrel file's named exports contains the specifier (`export { xasA } from"./a";`, `export*asAfrom"./a"`, `export { a, b }`, `exportconstA`, `exportdefaultA (thenameisdefault)`), whichmeansthestarre-exportisnotused. SoRspackwillstillbuildthestarre-export if:
990
+
1. barrelfileisnotsideeffectsfree
991
+
2. the star re-exportisused
992
+
993
+
> For more details please checkout: [RFC: Lazy make for reexports in side effects free barrel file](https://github.com/web-infra-dev/rspack/discussions/11273)
Copy file name to clipboardExpand all lines: website/docs/en/config/optimization.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -296,7 +296,7 @@ export default {
296
296
};
297
297
```
298
298
299
-
`flag` 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.
299
+
`flag` tells Rspack to recognise the sideEffects flag in package.json or [module.rule.sideEffects](/config/module#rulesideeffects) to skip over modules which are flagged to contain no side effects when exports are not used.
300
300
301
301
`true` tells Rspack not only recognise the sideEffects flag, but also analyse modules which are not flagged explicitly, and determine if they have side effects or not.
0 commit comments