From 5007edf1a410d70ee5d084b1049f06c81748d3a0 Mon Sep 17 00:00:00 2001 From: Kurtil Date: Fri, 28 Jan 2022 13:34:21 +0100 Subject: [PATCH 1/3] revert: fix(lib-mode): do not minify lib mode es output This reverts commit 06d86e4a2e90ca916a43d450bca1e6c28bc4bfe2. --- packages/vite/src/node/plugins/esbuild.ts | 8 +------- packages/vite/src/node/plugins/terser.ts | 6 ------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index b9e2b74efdca1d..10e6a117634b1a 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -227,13 +227,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 } diff --git a/packages/vite/src/node/plugins/terser.ts b/packages/vite/src/node/plugins/terser.ts index 29f4d5c172ce67..edabeffbcaf478 100644 --- a/packages/vite/src/node/plugins/terser.ts +++ b/packages/vite/src/node/plugins/terser.ts @@ -35,12 +35,6 @@ export function terserPlugin(config: ResolvedConfig): Plugin { return null } - // Do not minify ES lib output since that would remove pure annotations - // and break tree-shaking. - if (config.build.lib && outputOptions.format === 'es') { - return null - } - // Lazy load worker. worker ||= makeWorker() From 37db18b429ee6d9d7e259eeede9868703c3a0976 Mon Sep 17 00:00:00 2001 From: Kurtil Date: Fri, 28 Jan 2022 13:45:56 +0100 Subject: [PATCH 2/3] fix: minify default is false if lib or "esbuild" --- packages/vite/src/node/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 84ffb93b432f15..92b0adc1c32704 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -251,7 +251,7 @@ export function resolveBuildOptions( cssTarget: false, sourcemap: false, rollupOptions: {}, - minify: raw?.ssr ? false : 'esbuild', + minify: raw?.ssr || raw?.lib ? false : 'esbuild', terserOptions: {}, write: true, emptyOutDir: null, From c7360f4987bbf755ab8011155848f5cf5f5f93ea Mon Sep 17 00:00:00 2001 From: Kurtil Date: Fri, 28 Jan 2022 13:50:17 +0100 Subject: [PATCH 3/3] docs(lib-mode): remove build.minify es lib limitation --- docs/config/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 233e08b8f864e3..4a7c81c433968e 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -801,8 +801,6 @@ export default defineConfig({ Set to `false` to disable minification, or specify the minifier to use. The default is [Esbuild](https://github.com/evanw/esbuild) which is 20 ~ 40x faster than terser and only 1 ~ 2% worse compression. [Benchmarks](https://github.com/privatenumber/minification-benchmarks) - Note the `build.minify` option is not available when using the `'es'` format in lib mode. - ### build.terserOptions - **Type:** `TerserOptions`