Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tsconfig jsx overrides esbuild options, reverts #10374 #10714

Merged
merged 1 commit into from Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions docs/guide/features.md
Expand Up @@ -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 `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.
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.

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).
Expand All @@ -71,13 +71,10 @@ 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)
- [`jsx`](https://www.typescriptlang.org/tsconfig#jsx)
- [`preserveValueImports`](https://www.typescriptlang.org/tsconfig#preserveValueImports)
- [`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.

Expand Down
20 changes: 7 additions & 13 deletions packages/vite/src/node/plugins/esbuild.ts
Expand Up @@ -50,15 +50,12 @@ export type ESBuildTransformResult = Omit<TransformResult, 'map'> & {
type TSConfigJSON = {
extends?: string
compilerOptions?: {
alwaysStrict?: boolean
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve'
target?: string
jsxFactory?: string
jsxFragmentFactory?: string
jsxImportSource?: string
preserveValueImports?: boolean
target?: string
useDefineForClassFields?: boolean
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
preserveValueImports?: boolean
}
[key: string]: any
}
Expand Down Expand Up @@ -95,15 +92,12 @@ export async function transformWithEsbuild(
// these fields would affect the compilation result
// https://esbuild.github.io/content-types/#tsconfig-json
const meaningfulFields: Array<keyof TSCompilerOptions> = [
'alwaysStrict',
'importsNotUsedAsValues',
'jsx',
'target',
'jsxFactory',
'jsxFragmentFactory',
'jsxImportSource',
'preserveValueImports',
'target',
'useDefineForClassFields'
'useDefineForClassFields',
'importsNotUsedAsValues',
'preserveValueImports'
]
const compilerOptionsForFile: TSCompilerOptions = {}
if (loader === 'ts' || loader === 'tsx') {
Expand Down