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

WIP: feat: enable rspack newTreeShaking #1949

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
},
"pnpm": {
"overrides": {
"@rspack/core": "0.5.9-canary-845e837-20240327011520",
"@rspack/plugin-react-refresh": "0.5.9-canary-845e837-20240327011520",
"esbuild": "~0.19.0",
"array.prototype.flat": "npm:@nolyfill/array.prototype.flat@1.0.24",
"@rsbuild/core": "link:packages/core",
Expand Down
18 changes: 7 additions & 11 deletions packages/core/src/provider/plugins/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ 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;
// }
// });
api.modifyRspackConfig((config) => {
// rspack will be enabled by default in the next minor version
config.experiments ||= {};
config.experiments.rspackFuture ||= {};
config.experiments.rspackFuture.newTreeshaking = true;
});
},
});
3 changes: 3 additions & 0 deletions packages/core/tests/__snapshots__/builder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = `
},
"experiments": {
"asyncWebAssembly": true,
"rspackFuture": {
"newTreeshaking": true,
},
},
"infrastructureLogging": {
"level": "error",
Expand Down
12 changes: 12 additions & 0 deletions packages/core/tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
"experiments": {
"asyncWebAssembly": true,
"rspackFuture": {
"newTreeshaking": true,
},
},
"infrastructureLogging": {
"level": "error",
Expand Down Expand Up @@ -721,6 +724,9 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
},
"experiments": {
"asyncWebAssembly": true,
"rspackFuture": {
"newTreeshaking": true,
},
},
"infrastructureLogging": {
"level": "error",
Expand Down Expand Up @@ -1487,6 +1493,9 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
"experiments": {
"asyncWebAssembly": true,
"rspackFuture": {
"newTreeshaking": true,
},
},
"infrastructureLogging": {
"level": "error",
Expand Down Expand Up @@ -1903,6 +1912,9 @@ exports[`tools.rspack > should match snapshot 1`] = `
},
"experiments": {
"asyncWebAssembly": true,
"rspackFuture": {
"newTreeshaking": true,
},
},
"infrastructureLogging": {
"level": "error",
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-react/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ exports[`plugins/react > should work with swc-loader 1`] = `
},
"experiments": {
"asyncWebAssembly": true,
"rspackFuture": {
"newTreeshaking": true,
},
},
"infrastructureLogging": {
"level": "error",
Expand Down
114 changes: 58 additions & 56 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.