Skip to content

Commit

Permalink
fix: Allow enabling esbuild.minifyWhitespace for es format in lib mode (
Browse files Browse the repository at this point in the history
fix vitejs#6555)

To produce es bundles that can be tree-shaken, lib mode disables
minifyWhitespace by default when using the es format. But there are
cases where we want an es bundle that is as small as possible and that
does not need to be tree-shakable. This change allows minifyWhitespace
to be re-enabled if the user so desires.
  • Loading branch information
WIStudent committed Nov 22, 2024
1 parent dc60410 commit f2cfa68
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'`.

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/plugins/esbuild.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('resolveEsbuildTranspileOptions', () => {
minify: false,
minifyIdentifiers: true,
minifySyntax: true,
minifyWhitespace: false,
minifyWhitespace: true,
treeShaking: true,
supported: {
'dynamic-import': true,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f2cfa68

Please sign in to comment.