From 6a37d151226aaf477b8157fab10a789cc8d62e17 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Fri, 6 May 2022 14:40:57 +0200 Subject: [PATCH 1/7] build: bump targets --- packages/create-vite/template-lit-ts/tsconfig.json | 6 +++--- packages/create-vite/template-lit-ts/tsconfig.node.json | 4 ++-- .../create-vite/template-preact-ts/tsconfig.node.json | 4 ++-- packages/create-vite/template-react-ts/tsconfig.node.json | 4 ++-- packages/create-vite/template-svelte-ts/tsconfig.json | 4 ++-- .../create-vite/template-svelte-ts/tsconfig.node.json | 4 ++-- packages/create-vite/template-svelte/jsconfig.json | 6 +++--- packages/create-vite/template-vue-ts/tsconfig.json | 8 ++++---- packages/create-vite/template-vue-ts/tsconfig.node.json | 4 ++-- packages/plugin-react/tsconfig.json | 2 +- packages/plugin-vue/tsconfig.json | 2 +- packages/vite/rollup.config.js | 6 +++--- packages/vite/src/client/tsconfig.json | 2 +- packages/vite/src/node/tsconfig.json | 2 +- packages/vite/tsconfig.base.json | 2 +- playground/hmr/tsconfig.json | 6 +++--- playground/tsconfig.json | 6 +++--- scripts/tsconfig.json | 6 +++--- 18 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/create-vite/template-lit-ts/tsconfig.json b/packages/create-vite/template-lit-ts/tsconfig.json index 91a731fd8619d4..b080b2b2cd41a7 100644 --- a/packages/create-vite/template-lit-ts/tsconfig.json +++ b/packages/create-vite/template-lit-ts/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "module": "esnext", - "lib": ["es2017", "dom", "dom.iterable"], + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], "declaration": true, "emitDeclarationOnly": true, "outDir": "./types", @@ -10,7 +10,7 @@ "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, - "moduleResolution": "node", + "moduleResolution": "Node", "isolatedModules": true, "allowSyntheticDefaultImports": true, "experimentalDecorators": true, diff --git a/packages/create-vite/template-lit-ts/tsconfig.node.json b/packages/create-vite/template-lit-ts/tsconfig.node.json index e993792cb12c9d..65dbdb96ae5dcf 100644 --- a/packages/create-vite/template-lit-ts/tsconfig.node.json +++ b/packages/create-vite/template-lit-ts/tsconfig.node.json @@ -1,8 +1,8 @@ { "compilerOptions": { "composite": true, - "module": "esnext", - "moduleResolution": "node" + "module": "ESNext", + "moduleResolution": "Node" }, "include": ["vite.config.ts"] } diff --git a/packages/create-vite/template-preact-ts/tsconfig.node.json b/packages/create-vite/template-preact-ts/tsconfig.node.json index e993792cb12c9d..65dbdb96ae5dcf 100644 --- a/packages/create-vite/template-preact-ts/tsconfig.node.json +++ b/packages/create-vite/template-preact-ts/tsconfig.node.json @@ -1,8 +1,8 @@ { "compilerOptions": { "composite": true, - "module": "esnext", - "moduleResolution": "node" + "module": "ESNext", + "moduleResolution": "Node" }, "include": ["vite.config.ts"] } diff --git a/packages/create-vite/template-react-ts/tsconfig.node.json b/packages/create-vite/template-react-ts/tsconfig.node.json index e993792cb12c9d..65dbdb96ae5dcf 100644 --- a/packages/create-vite/template-react-ts/tsconfig.node.json +++ b/packages/create-vite/template-react-ts/tsconfig.node.json @@ -1,8 +1,8 @@ { "compilerOptions": { "composite": true, - "module": "esnext", - "moduleResolution": "node" + "module": "ESNext", + "moduleResolution": "Node" }, "include": ["vite.config.ts"] } diff --git a/packages/create-vite/template-svelte-ts/tsconfig.json b/packages/create-vite/template-svelte-ts/tsconfig.json index 96bfd81aaf1203..d38303196ae8dc 100644 --- a/packages/create-vite/template-svelte-ts/tsconfig.json +++ b/packages/create-vite/template-svelte-ts/tsconfig.json @@ -1,9 +1,9 @@ { "extends": "@tsconfig/svelte/tsconfig.json", "compilerOptions": { - "target": "esnext", + "target": "ESNext", "useDefineForClassFields": true, - "module": "esnext", + "module": "ESNext", "resolveJsonModule": true, "baseUrl": ".", /** diff --git a/packages/create-vite/template-svelte-ts/tsconfig.node.json b/packages/create-vite/template-svelte-ts/tsconfig.node.json index e993792cb12c9d..65dbdb96ae5dcf 100644 --- a/packages/create-vite/template-svelte-ts/tsconfig.node.json +++ b/packages/create-vite/template-svelte-ts/tsconfig.node.json @@ -1,8 +1,8 @@ { "compilerOptions": { "composite": true, - "module": "esnext", - "moduleResolution": "node" + "module": "ESNext", + "moduleResolution": "Node" }, "include": ["vite.config.ts"] } diff --git a/packages/create-vite/template-svelte/jsconfig.json b/packages/create-vite/template-svelte/jsconfig.json index 42585941e160b7..ee5e92f298e484 100644 --- a/packages/create-vite/template-svelte/jsconfig.json +++ b/packages/create-vite/template-svelte/jsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { - "moduleResolution": "node", - "target": "esnext", - "module": "esnext", + "moduleResolution": "Node", + "target": "ESNext", + "module": "ESNext", /** * svelte-preprocess cannot figure out whether you have * a value or a type, so tell TypeScript to enforce using diff --git a/packages/create-vite/template-vue-ts/tsconfig.json b/packages/create-vite/template-vue-ts/tsconfig.json index bcc4abda4c57f0..d4aefa2c929dc2 100644 --- a/packages/create-vite/template-vue-ts/tsconfig.json +++ b/packages/create-vite/template-vue-ts/tsconfig.json @@ -1,16 +1,16 @@ { "compilerOptions": { - "target": "esnext", + "target": "ESNext", "useDefineForClassFields": true, - "module": "esnext", - "moduleResolution": "node", + "module": "ESNext", + "moduleResolution": "Node", "strict": true, "jsx": "preserve", "sourceMap": true, "resolveJsonModule": true, "isolatedModules": true, "esModuleInterop": true, - "lib": ["esnext", "dom"], + "lib": ["ESNext", "DOM"], "skipLibCheck": true }, "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], diff --git a/packages/create-vite/template-vue-ts/tsconfig.node.json b/packages/create-vite/template-vue-ts/tsconfig.node.json index e993792cb12c9d..65dbdb96ae5dcf 100644 --- a/packages/create-vite/template-vue-ts/tsconfig.node.json +++ b/packages/create-vite/template-vue-ts/tsconfig.node.json @@ -1,8 +1,8 @@ { "compilerOptions": { "composite": true, - "module": "esnext", - "moduleResolution": "node" + "module": "ESNext", + "moduleResolution": "Node" }, "include": ["vite.config.ts"] } diff --git a/packages/plugin-react/tsconfig.json b/packages/plugin-react/tsconfig.json index c20adf0da4b86f..0068f94384be8f 100644 --- a/packages/plugin-react/tsconfig.json +++ b/packages/plugin-react/tsconfig.json @@ -3,7 +3,7 @@ "exclude": ["**/*.spec.ts"], "compilerOptions": { "outDir": "dist", - "target": "ES2018", + "target": "ES2020", "module": "CommonJS", "moduleResolution": "Node", "strict": true, diff --git a/packages/plugin-vue/tsconfig.json b/packages/plugin-vue/tsconfig.json index 6165780e190e25..ca2267f0bf3c35 100644 --- a/packages/plugin-vue/tsconfig.json +++ b/packages/plugin-vue/tsconfig.json @@ -3,7 +3,7 @@ "exclude": ["**/*.spec.ts"], "compilerOptions": { "outDir": "dist", - "target": "ES2019", + "target": "ES2020", "module": "commonjs", "moduleResolution": "node", "strict": true, diff --git a/packages/vite/rollup.config.js b/packages/vite/rollup.config.js index 93f4f33bdec398..450217f91d8a80 100644 --- a/packages/vite/rollup.config.js +++ b/packages/vite/rollup.config.js @@ -19,7 +19,7 @@ const envConfig = { input: path.resolve(__dirname, 'src/client/env.ts'), plugins: [ typescript({ - target: 'es2018', + target: 'es2020', include: ['src/client/env.ts'], baseUrl: path.resolve(__dirname, 'src/env'), paths: { @@ -41,7 +41,7 @@ const clientConfig = { external: ['./env', '@vite/env'], plugins: [ typescript({ - target: 'es2018', + target: 'es2020', include: ['src/client/**/*.ts'], baseUrl: path.resolve(__dirname, 'src/client'), paths: { @@ -128,7 +128,7 @@ const createNodeConfig = (isProduction) => { typescript({ tsconfig: 'src/node/tsconfig.json', module: 'esnext', - target: 'es2019', + target: 'es2020', include: ['src/**/*.ts', 'types/**'], exclude: ['src/**/__tests__/**'], esModuleInterop: true, diff --git a/packages/vite/src/client/tsconfig.json b/packages/vite/src/client/tsconfig.json index 1fd43f8327decc..c6421264c50409 100644 --- a/packages/vite/src/client/tsconfig.json +++ b/packages/vite/src/client/tsconfig.json @@ -3,7 +3,7 @@ "include": ["./", "../../types"], "compilerOptions": { "outDir": "../../dist/client", - "module": "esnext", + "module": "ESNext", "types": [], "lib": ["ESNext", "DOM"], "declaration": false diff --git a/packages/vite/src/node/tsconfig.json b/packages/vite/src/node/tsconfig.json index 166ddb4a1d5935..049288bad3f952 100644 --- a/packages/vite/src/node/tsconfig.json +++ b/packages/vite/src/node/tsconfig.json @@ -5,7 +5,7 @@ "compilerOptions": { // compile away optional-chaining-operator // node support table: https://node.green/#ES2020-features-optional-chaining-operator----- - "target": "ES2019", + "target": "ES2020", "outDir": "../../dist/node", "module": "commonjs", "lib": ["ESNext", "DOM"], diff --git a/packages/vite/tsconfig.base.json b/packages/vite/tsconfig.base.json index b76fc881a81dc9..1b417945798eaa 100644 --- a/packages/vite/tsconfig.base.json +++ b/packages/vite/tsconfig.base.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES2018", + "target": "ES2020", "moduleResolution": "node", "strict": true, "declaration": true, diff --git a/playground/hmr/tsconfig.json b/playground/hmr/tsconfig.json index e920e674091b5e..b9fb7448b41d60 100644 --- a/playground/hmr/tsconfig.json +++ b/playground/hmr/tsconfig.json @@ -3,12 +3,12 @@ "include": ["."], "exclude": ["**/dist/**", "**/__tests__/**"], "compilerOptions": { - "target": "es2019", - "module": "esnext", + "target": "ES2020", + "module": "ESNext", "outDir": "dist", "allowJs": true, "esModuleInterop": true, - "moduleResolution": "node", + "moduleResolution": "Node", "baseUrl": ".", "jsx": "preserve", "types": ["vite/client", "node"] diff --git a/playground/tsconfig.json b/playground/tsconfig.json index ada2a60bff6cff..cbf237ee6d4653 100644 --- a/playground/tsconfig.json +++ b/playground/tsconfig.json @@ -2,14 +2,14 @@ "include": ["."], "exclude": ["**/dist/**"], "compilerOptions": { - "target": "es2019", - "module": "esnext", + "target": "ES2020", + "module": "ESNext", "outDir": "dist", "baseUrl": ".", "allowJs": true, "esModuleInterop": true, "resolveJsonModule": true, - "moduleResolution": "node", + "moduleResolution": "Node", "skipLibCheck": true, "noUnusedLocals": true, "jsx": "preserve", diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 92cbe98fb03740..3c25c197e231b4 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -2,9 +2,9 @@ "$schema": "https://json.schemastore.org/tsconfig", "include": ["."], "compilerOptions": { - "module": "commonjs", - "target": "es2019", - "moduleResolution": "node", + "module": "CommonJS", + "target": "ES2020", + "moduleResolution": "Node", "strict": true, "esModuleInterop": true, "skipLibCheck": true, From b993f2748a53d63327e936a08c76f5e42823bc73 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Fri, 6 May 2022 16:48:54 +0200 Subject: [PATCH 2/7] chore: mark stuff --- docs/config/index.md | 2 +- docs/guide/assets.md | 3 +++ docs/guide/build.md | 2 +- packages/vite/src/node/build.ts | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 1c61f2bef5b7ac..9a602b8da8fcb7 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -745,7 +745,7 @@ export default defineConfig({ 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'`, `'esnext'` will be forced down to `'es2019'`. + - If the [`build.minify`](#build-minify) option is `'terser'`, `'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/docs/guide/assets.md b/docs/guide/assets.md index 9776dcdd032f35..205eacb817b7f5 100644 --- a/docs/guide/assets.md +++ b/docs/guide/assets.md @@ -115,5 +115,8 @@ This pattern does not work if you are using Vite for Server-Side Rendering, beca ::: ::: warning Esbuild target config is necessary + + + This pattern needs esbuild target to be set to `es2020` or higher. `vite@2.x` use `es2019` as default target. Set [build-target](https://vitejs.dev/config/#build-target) and [optimizedeps.esbuildoptions.target](https://vitejs.dev/config/#optimizedeps-esbuildoptions) to `es2020` or higher if you intend to use this partten. ::: diff --git a/docs/guide/build.md b/docs/guide/build.md index 358745d02f2cf1..8e09b747619ac3 100644 --- a/docs/guide/build.md +++ b/docs/guide/build.md @@ -10,7 +10,7 @@ The production bundle assumes support for modern JavaScript. By default, Vite ta defaults and supports es6-module and supports es6-module-dynamic-import, not opera > 0, not samsung > 0, not and_qq > 0 ``` -You can specify custom targets via the [`build.target` config option](/config/#build-target), where the lowest target is `es2015`. +You can specify custom targets via the [`build.target` config option](/config/#build-target), where the lowest target is `es2015`. Note that by default, Vite only handles syntax transforms and **does not cover polyfills by default**. You can check out [Polyfill.io](https://polyfill.io/v3/) which is a service that automatically generates polyfill bundles based on the user's browser UserAgent string. diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 550af9d13af389..b75fb6d7171ddf 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -253,7 +253,7 @@ export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions { ] } else if (resolved.target === 'esnext' && resolved.minify === 'terser') { // esnext + terser: limit to es2019 so it can be minified by terser - resolved.target = 'es2019' + resolved.target = 'es2020' } if (!resolved.cssTarget) { From 11b6818ab6088d58e124dce8b3f624df8c10a973 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Wed, 18 May 2022 17:04:00 +0200 Subject: [PATCH 3/7] build: bump more targets --- packages/plugin-vue-jsx/tsconfig.json | 2 +- packages/vite/src/node/tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugin-vue-jsx/tsconfig.json b/packages/plugin-vue-jsx/tsconfig.json index c20adf0da4b86f..0068f94384be8f 100644 --- a/packages/plugin-vue-jsx/tsconfig.json +++ b/packages/plugin-vue-jsx/tsconfig.json @@ -3,7 +3,7 @@ "exclude": ["**/*.spec.ts"], "compilerOptions": { "outDir": "dist", - "target": "ES2018", + "target": "ES2020", "module": "CommonJS", "moduleResolution": "Node", "strict": true, diff --git a/packages/vite/src/node/tsconfig.json b/packages/vite/src/node/tsconfig.json index 049288bad3f952..5f600e33cc0951 100644 --- a/packages/vite/src/node/tsconfig.json +++ b/packages/vite/src/node/tsconfig.json @@ -7,7 +7,7 @@ // node support table: https://node.green/#ES2020-features-optional-chaining-operator----- "target": "ES2020", "outDir": "../../dist/node", - "module": "commonjs", + "module": "CommonJS", "lib": ["ESNext", "DOM"], "sourceMap": true } From c52e155a60b6377236d5f41cd846c6925ff55164 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Wed, 18 May 2022 17:13:08 +0200 Subject: [PATCH 4/7] chore: remove mark --- docs/guide/assets.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/guide/assets.md b/docs/guide/assets.md index 205eacb817b7f5..9776dcdd032f35 100644 --- a/docs/guide/assets.md +++ b/docs/guide/assets.md @@ -115,8 +115,5 @@ This pattern does not work if you are using Vite for Server-Side Rendering, beca ::: ::: warning Esbuild target config is necessary - - - This pattern needs esbuild target to be set to `es2020` or higher. `vite@2.x` use `es2019` as default target. Set [build-target](https://vitejs.dev/config/#build-target) and [optimizedeps.esbuildoptions.target](https://vitejs.dev/config/#optimizedeps-esbuildoptions) to `es2020` or higher if you intend to use this partten. ::: From 42030f48f630a2f9fe9b61211f6720f133212e33 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Wed, 18 May 2022 18:19:33 +0200 Subject: [PATCH 5/7] chore: apply suggestions --- docs/config/index.md | 2 +- docs/guide/build.md | 2 +- packages/vite/src/node/build.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 9a602b8da8fcb7..c885020eca28d3 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -745,7 +745,7 @@ export default defineConfig({ 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'`, `'esnext'` will be forced down to `'es2019'`. + - If the [`build.minify`](#build-minify) option is `'terser'`, `'esnext'` will be forced down to `'es2021'`. - 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/docs/guide/build.md b/docs/guide/build.md index 8e09b747619ac3..358745d02f2cf1 100644 --- a/docs/guide/build.md +++ b/docs/guide/build.md @@ -10,7 +10,7 @@ The production bundle assumes support for modern JavaScript. By default, Vite ta defaults and supports es6-module and supports es6-module-dynamic-import, not opera > 0, not samsung > 0, not and_qq > 0 ``` -You can specify custom targets via the [`build.target` config option](/config/#build-target), where the lowest target is `es2015`. +You can specify custom targets via the [`build.target` config option](/config/#build-target), where the lowest target is `es2015`. Note that by default, Vite only handles syntax transforms and **does not cover polyfills by default**. You can check out [Polyfill.io](https://polyfill.io/v3/) which is a service that automatically generates polyfill bundles based on the user's browser UserAgent string. diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index b75fb6d7171ddf..cdfc1540bda5cc 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -252,8 +252,8 @@ export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions { 'safari13' // transpile nullish coalescing ] } else if (resolved.target === 'esnext' && resolved.minify === 'terser') { - // esnext + terser: limit to es2019 so it can be minified by terser - resolved.target = 'es2020' + // esnext + terser: limit to es2021 so it can be minified by terser + resolved.target = 'es2021' } if (!resolved.cssTarget) { From 85b2df4212e2547bd0b3dde00f85b5038adf8c88 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Wed, 18 May 2022 18:43:19 +0200 Subject: [PATCH 6/7] chore: remove stale comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 翠 / green --- packages/vite/src/node/tsconfig.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/vite/src/node/tsconfig.json b/packages/vite/src/node/tsconfig.json index 5f600e33cc0951..4116608b4d5a4f 100644 --- a/packages/vite/src/node/tsconfig.json +++ b/packages/vite/src/node/tsconfig.json @@ -3,8 +3,6 @@ "include": ["./", "../../types"], "exclude": ["**/__tests__"], "compilerOptions": { - // compile away optional-chaining-operator - // node support table: https://node.green/#ES2020-features-optional-chaining-operator----- "target": "ES2020", "outDir": "../../dist/node", "module": "CommonJS", From dc0d870b7eae3443726772f7c1a109d4d3ebecea Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Wed, 18 May 2022 20:14:19 +0200 Subject: [PATCH 7/7] chore: change target also for legacy plugin --- packages/plugin-legacy/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-legacy/tsconfig.json b/packages/plugin-legacy/tsconfig.json index c20adf0da4b86f..0068f94384be8f 100644 --- a/packages/plugin-legacy/tsconfig.json +++ b/packages/plugin-legacy/tsconfig.json @@ -3,7 +3,7 @@ "exclude": ["**/*.spec.ts"], "compilerOptions": { "outDir": "dist", - "target": "ES2018", + "target": "ES2020", "module": "CommonJS", "moduleResolution": "Node", "strict": true,