Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Re-enable minifying es lib #6670

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 0 additions & 6 deletions packages/vite/src/node/plugins/terser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down