From f542727917650c18e450d9b69e8ec17b248a7117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Fri, 14 Oct 2022 22:44:58 +0900 Subject: [PATCH] feat: update esbuild compilation affecting fields (#10374) --- docs/guide/features.md | 7 +++++-- packages/vite/src/node/plugins/esbuild.ts | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/guide/features.md b/docs/guide/features.md index 0f69035a71dea5..f41e5d8ce9bd31 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -57,7 +57,7 @@ However, some libraries (e.g. [`vue`](https://github.com/vuejs/core/issues/1228) #### `useDefineForClassFields` -Starting from Vite 2.5.0, the default value will be `true` if the TypeScript target is `ESNext`. It is consistent with the [behavior of `tsc` 4.3.2 and later](https://github.com/microsoft/TypeScript/pull/42663). It is also the standard ECMAScript runtime behavior. +Starting from Vite 2.5.0, the default value will be `true` if the TypeScript target is `ES2022` or higher including `ESNext`. It is consistent with the [behavior of `tsc` 4.3.2 and later](https://github.com/microsoft/TypeScript/pull/42663). It is also the standard ECMAScript runtime behavior. But it may be counter-intuitive for those coming from other programming languages or older versions of TypeScript. You can read more about the transition in the [TypeScript 3.7 release notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier). @@ -71,10 +71,13 @@ But a few libraries haven't transitioned to this new default yet, including [`li #### Other Compiler Options Affecting the Build Result - [`extends`](https://www.typescriptlang.org/tsconfig#extends) +- [`alwaysStrict`](https://www.typescriptlang.org/tsconfig#alwaysStrict) - [`importsNotUsedAsValues`](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues) -- [`preserveValueImports`](https://www.typescriptlang.org/tsconfig#preserveValueImports) +- [`jsx`](https://www.typescriptlang.org/tsconfig#jsx) - [`jsxFactory`](https://www.typescriptlang.org/tsconfig#jsxFactory) - [`jsxFragmentFactory`](https://www.typescriptlang.org/tsconfig#jsxFragmentFactory) +- [`jsxImportSource`](https://www.typescriptlang.org/tsconfig#jsxImportSource) +- [`preserveValueImports`](https://www.typescriptlang.org/tsconfig#preserveValueImports) If migrating your codebase to `"isolatedModules": true` is an unsurmountable effort, you may be able to get around it with a third-party plugin such as [rollup-plugin-friendly-type-imports](https://www.npmjs.com/package/rollup-plugin-friendly-type-imports). However, this approach is not officially supported by Vite. diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 43c319f2713761..cb1899eabc5e1c 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -50,12 +50,15 @@ export type ESBuildTransformResult = Omit & { type TSConfigJSON = { extends?: string compilerOptions?: { - target?: string + alwaysStrict?: boolean + importsNotUsedAsValues?: 'remove' | 'preserve' | 'error' + jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve' jsxFactory?: string jsxFragmentFactory?: string - useDefineForClassFields?: boolean - importsNotUsedAsValues?: 'remove' | 'preserve' | 'error' + jsxImportSource?: string preserveValueImports?: boolean + target?: string + useDefineForClassFields?: boolean } [key: string]: any } @@ -92,12 +95,15 @@ export async function transformWithEsbuild( // these fields would affect the compilation result // https://esbuild.github.io/content-types/#tsconfig-json const meaningfulFields: Array = [ - 'target', + 'alwaysStrict', + 'importsNotUsedAsValues', + 'jsx', 'jsxFactory', 'jsxFragmentFactory', - 'useDefineForClassFields', - 'importsNotUsedAsValues', - 'preserveValueImports' + 'jsxImportSource', + 'preserveValueImports', + 'target', + 'useDefineForClassFields' ] const compilerOptionsForFile: TSCompilerOptions = {} if (loader === 'ts' || loader === 'tsx') {