Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable new tree shaking in production #1839

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"svgr",
"systemjs",
"transpiling",
"treeshaking",
"tsbuildinfo",
"unocss",
"vitest",
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/provider/plugins/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ import type { RsbuildPlugin } from '../../types';
export const pluginTransition = (): RsbuildPlugin => ({
name: 'rsbuild:transition',

setup() {
setup(api) {
process.env.RSPACK_CONFIG_VALIDATE = 'loose-silent';

// improve kill process performance
// https://github.com/web-infra-dev/rspack/pull/5486
process.env.WATCHPACK_WATCHER_LIMIT ||= '20';

api.modifyRspackConfig((config, { isProd }) => {
// only enable new tree shaking in production build,
// because Rspack still has some problems when using it in dev mode.
// such as https://github.com/web-infra-dev/rspack/issues/5887
if (isProd) {
config.experiments ||= {};
config.experiments.rspackFuture ||= {};
config.experiments.rspackFuture.newTreeshaking = true;
}
});
},
});
3 changes: 3 additions & 0 deletions packages/core/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
},
"experiments": {
"asyncWebAssembly": true,
"rspackFuture": {
"newTreeshaking": true,
},
},
"infrastructureLogging": {
"level": "error",
Expand Down