Skip to content

Commit bd8723e

Browse files
committed
fix: only downgrade target to es2019 when actually using terser
1 parent 4cbb40d commit bd8723e

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

docs/config/index.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ export default async ({ command, mode }) => {
437437

438438
When using `server.middlewareMode` and `server.https`, setting `server.hmr.server` to your HTTPS server will process HMR secure connection requests through your server. This can be helpful when using self-signed certificates.
439439

440-
441440
### server.watch
442441

443442
- **Type:** `object`
@@ -456,6 +455,7 @@ export default async ({ command, mode }) => {
456455
- **Related:** [SSR - Setting Up the Dev Server](/guide/ssr#setting-up-the-dev-server)
457456

458457
- **Example:**
458+
459459
```js
460460
const express = require('express')
461461
const { createServer: createViteServer } = require('vite')
@@ -524,7 +524,10 @@ createServer()
524524

525525
Browser compatibility target for the final bundle. The default value is a Vite special value, `'modules'`, which targets [browsers with native ES module support](https://caniuse.com/es6-module).
526526

527-
Another special value is 'esnext' - which only performs minimal transpiling (for minification compat) and assumes native dynamic imports support.
527+
Another special value is `'esnext'` - which assumes native dynamic imports support and will transpile as little as possible:
528+
529+
- If the [`build.minify`](#build-minify) option is `'terser'` (the default), `'esnext'` will be forced down to `'es2019'`.
530+
- In other cases, it will perform no transpilation at all.
528531

529532
The transform is performed with esbuild and the value should be a valid [esbuild target option](https://esbuild.github.io/api/#target). Custom targets can either be a ES version (e.g. `es2015`), a browser with version (e.g. `chrome58`), or an array of multiple target strings.
530533

packages/vite/src/node/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions {
241241
'chrome87',
242242
'safari13.1'
243243
]
244-
} else if (resolved.target === 'esnext' && resolved.minify !== 'esbuild') {
244+
} else if (resolved.target === 'esnext' && resolved.minify === 'terser') {
245245
// esnext + terser: limit to es2019 so it can be minified by terser
246246
resolved.target = 'es2019'
247247
}

packages/vite/src/node/plugins/esbuild.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => {
127127

128128
const target = config.build.target
129129
const minify = config.build.minify === 'esbuild'
130-
if (!target && !minify) {
130+
if ((!target || target === 'esnext') && !minify) {
131131
return null
132132
}
133133
return transformWithEsbuild(code, chunk.fileName, {

0 commit comments

Comments
 (0)