diff --git a/docs/config/build-options.md b/docs/config/build-options.md index 3419070bd474a6..7d8d6fdaceb619 100644 --- a/docs/config/build-options.md +++ b/docs/config/build-options.md @@ -230,7 +230,7 @@ During the SSR build, static assets aren't emitted as it is assumed they would b 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 does not minify whitespaces when using the `'es'` format in lib mode, as it removes pure annotations and breaks tree-shaking. +Note the `build.minify` option does not minify whitespaces when using the `'es'` format in lib mode, as it removes pure annotations and breaks tree-shaking. To force whitespace minification for `'es'` format in lib mode, explicitly set `esbuild.minifyWhitespace` to `true`. Terser must be installed when it is set to `'terser'`. diff --git a/packages/vite/src/node/__tests__/plugins/esbuild.spec.ts b/packages/vite/src/node/__tests__/plugins/esbuild.spec.ts index 936415f9c33826..ae16fbe45b65f7 100644 --- a/packages/vite/src/node/__tests__/plugins/esbuild.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/esbuild.spec.ts @@ -201,7 +201,7 @@ describe('resolveEsbuildTranspileOptions', () => { minify: false, minifyIdentifiers: true, minifySyntax: true, - minifyWhitespace: false, + minifyWhitespace: true, treeShaking: true, supported: { 'dynamic-import': true, diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 6d3ffc86f33b06..c2f2b14525478f 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -426,7 +426,7 @@ export function resolveEsbuildTranspileOptions( minify: false, minifyIdentifiers: options.minifyIdentifiers ?? true, minifySyntax: options.minifySyntax ?? true, - minifyWhitespace: false, + minifyWhitespace: options.minifyWhitespace ?? false, treeShaking: true, } } else {