From 44ed5b10db48b1ad7e0b921fc485764303d4aac0 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Fri, 27 Dec 2024 18:06:11 +0100 Subject: [PATCH] fix: enable rollup default tree-shaking (#616) --- src/rollup/input.ts | 4 +--- .../treeshake/__snapshot__/treeshake.js.snapshot | 7 +++++++ .../__snapshot__/treeshake.min.js.snapshot | 1 + test/compile/treeshake/input.js | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 test/compile/treeshake/__snapshot__/treeshake.js.snapshot create mode 100644 test/compile/treeshake/__snapshot__/treeshake.min.js.snapshot create mode 100644 test/compile/treeshake/input.js diff --git a/src/rollup/input.ts b/src/rollup/input.ts index 464c5d54..4191eccc 100644 --- a/src/rollup/input.ts +++ b/src/rollup/input.ts @@ -258,9 +258,7 @@ export async function buildInputConfig( return externals.some((name) => id === name || id.startsWith(name + '/')) }, plugins, - treeshake: { - propertyReadSideEffects: false, - }, + treeshake: 'recommended', onwarn(warning, warn) { const code = warning.code || '' // Some may not have types, like CLI binary diff --git a/test/compile/treeshake/__snapshot__/treeshake.js.snapshot b/test/compile/treeshake/__snapshot__/treeshake.js.snapshot new file mode 100644 index 00000000..c15bd6bf --- /dev/null +++ b/test/compile/treeshake/__snapshot__/treeshake.js.snapshot @@ -0,0 +1,7 @@ +class Foo { + getFoo() { + return 'foo'; + } +} + +export { Foo }; diff --git a/test/compile/treeshake/__snapshot__/treeshake.min.js.snapshot b/test/compile/treeshake/__snapshot__/treeshake.min.js.snapshot new file mode 100644 index 00000000..7fb1f94c --- /dev/null +++ b/test/compile/treeshake/__snapshot__/treeshake.min.js.snapshot @@ -0,0 +1 @@ +class o{getFoo(){return"foo"}}export{o as Foo}; diff --git a/test/compile/treeshake/input.js b/test/compile/treeshake/input.js new file mode 100644 index 00000000..71fec92d --- /dev/null +++ b/test/compile/treeshake/input.js @@ -0,0 +1,14 @@ +class Foo { + getFoo() { + return 'foo' + } +} + +// This will be removed by treeshaking +class Bar { + getBar() { + return 'bar' + } +} + +export { Foo }