From 5dc0f72525c10b528bb5fdf44add67b10c74112c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Thu, 23 Jun 2022 16:12:31 +0900 Subject: [PATCH] feat: enable tree-shaking for lib es (#8737) --- packages/vite/src/node/plugins/esbuild.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 16c165bf288a98..64a243f3e2493e 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -237,12 +237,7 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => { } const target = config.build.target - const minify = - config.build.minify === 'esbuild' && - // Do not minify ES lib output since that would remove pure annotations - // and break tree-shaking - // https://github.com/vuejs/core/issues/2860#issuecomment-926882793 - !(config.build.lib && opts.format === 'es') + const minify = config.build.minify === 'esbuild' if ((!target || target === 'esnext') && !minify) { return null @@ -253,7 +248,10 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => { target: target || undefined, ...(minify ? { - minify, + // Do not minify ES lib output since that would remove pure annotations + // and break tree-shaking + // https://github.com/vuejs/core/issues/2860#issuecomment-926882793 + minify: !(config.build.lib && opts.format === 'es'), treeShaking: true, format: rollupToEsbuildFormatMap[opts.format] }