From bd8723eb36be368b4a45240e1f0159fbd40a81a4 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 22 Jun 2021 12:38:27 -0400 Subject: [PATCH] fix: only downgrade target to es2019 when actually using terser --- docs/config/index.md | 7 +++++-- packages/vite/src/node/build.ts | 2 +- packages/vite/src/node/plugins/esbuild.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 6c6370fb0c8dbf..cdd5740cdfdcb0 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -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` @@ -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') @@ -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. diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 5ee42a06f414de..653e03e4a71dc1 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -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' } diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 466c5f12073680..4a8fe70547924e 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -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, {