Skip to content

Commit

Permalink
fix: only downgrade target to es2019 when actually using terser
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 22, 2021
1 parent 4cbb40d commit bd8723e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ export default async ({ command, mode }) => {

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.


### server.watch

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

- **Example:**

```js
const express = require('express')
const { createServer: createViteServer } = require('vite')
Expand Down Expand Up @@ -524,7 +524,10 @@ createServer()

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).

Another special value is 'esnext' - which only performs minimal transpiling (for minification compat) and assumes native dynamic imports support.
Another special value is `'esnext'` - which assumes native dynamic imports support and will transpile as little as possible:

- If the [`build.minify`](#build-minify) option is `'terser'` (the default), `'esnext'` will be forced down to `'es2019'`.
- In other cases, it will perform no transpilation at all.

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.

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 @@ -241,7 +241,7 @@ export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions {
'chrome87',
'safari13.1'
]
} else if (resolved.target === 'esnext' && resolved.minify !== 'esbuild') {
} else if (resolved.target === 'esnext' && resolved.minify === 'terser') {
// esnext + terser: limit to es2019 so it can be minified by terser
resolved.target = 'es2019'
}
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 @@ -127,7 +127,7 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => {

const target = config.build.target
const minify = config.build.minify === 'esbuild'
if (!target && !minify) {
if ((!target || target === 'esnext') && !minify) {
return null
}
return transformWithEsbuild(code, chunk.fileName, {
Expand Down

0 comments on commit bd8723e

Please sign in to comment.