Skip to content

Commit f542727

Browse files
authoredOct 14, 2022
feat: update esbuild compilation affecting fields (#10374)
1 parent 5d9b810 commit f542727

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed
 

‎docs/guide/features.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ However, some libraries (e.g. [`vue`](https://github.com/vuejs/core/issues/1228)
5757

5858
#### `useDefineForClassFields`
5959

60-
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.
60+
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.
6161

6262
But it may be counter-intuitive for those coming from other programming languages or older versions of TypeScript.
6363
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
7171
#### Other Compiler Options Affecting the Build Result
7272

7373
- [`extends`](https://www.typescriptlang.org/tsconfig#extends)
74+
- [`alwaysStrict`](https://www.typescriptlang.org/tsconfig#alwaysStrict)
7475
- [`importsNotUsedAsValues`](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues)
75-
- [`preserveValueImports`](https://www.typescriptlang.org/tsconfig#preserveValueImports)
76+
- [`jsx`](https://www.typescriptlang.org/tsconfig#jsx)
7677
- [`jsxFactory`](https://www.typescriptlang.org/tsconfig#jsxFactory)
7778
- [`jsxFragmentFactory`](https://www.typescriptlang.org/tsconfig#jsxFragmentFactory)
79+
- [`jsxImportSource`](https://www.typescriptlang.org/tsconfig#jsxImportSource)
80+
- [`preserveValueImports`](https://www.typescriptlang.org/tsconfig#preserveValueImports)
7881

7982
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.
8083

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

+13-7
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@ export type ESBuildTransformResult = Omit<TransformResult, 'map'> & {
5050
type TSConfigJSON = {
5151
extends?: string
5252
compilerOptions?: {
53-
target?: string
53+
alwaysStrict?: boolean
54+
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
55+
jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve'
5456
jsxFactory?: string
5557
jsxFragmentFactory?: string
56-
useDefineForClassFields?: boolean
57-
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
58+
jsxImportSource?: string
5859
preserveValueImports?: boolean
60+
target?: string
61+
useDefineForClassFields?: boolean
5962
}
6063
[key: string]: any
6164
}
@@ -92,12 +95,15 @@ export async function transformWithEsbuild(
9295
// these fields would affect the compilation result
9396
// https://esbuild.github.io/content-types/#tsconfig-json
9497
const meaningfulFields: Array<keyof TSCompilerOptions> = [
95-
'target',
98+
'alwaysStrict',
99+
'importsNotUsedAsValues',
100+
'jsx',
96101
'jsxFactory',
97102
'jsxFragmentFactory',
98-
'useDefineForClassFields',
99-
'importsNotUsedAsValues',
100-
'preserveValueImports'
103+
'jsxImportSource',
104+
'preserveValueImports',
105+
'target',
106+
'useDefineForClassFields'
101107
]
102108
const compilerOptionsForFile: TSCompilerOptions = {}
103109
if (loader === 'ts' || loader === 'tsx') {

0 commit comments

Comments
 (0)
Please sign in to comment.