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

feat(node/plugins): esbuild options #11049

Merged
merged 6 commits into from Dec 7, 2022
Merged
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
37 changes: 31 additions & 6 deletions packages/vite/src/node/plugins/esbuild.ts
Expand Up @@ -50,12 +50,15 @@ export type ESBuildTransformResult = Omit<TransformResult, 'map'> & {
type TSConfigJSON = {
extends?: string
compilerOptions?: {
target?: string
alwaysStrict?: boolean
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
jsx?: 'preserve' | 'react' | 'react-jsx' | 'react-jsxdev'
jsxFactory?: string
jsxFragmentFactory?: string
useDefineForClassFields?: boolean
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
jsxImportSource?: string
preserveValueImports?: boolean
target?: string
useDefineForClassFields?: boolean
}
[key: string]: any
}
Expand Down Expand Up @@ -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<keyof TSCompilerOptions> = [
'target',
'alwaysStrict',
'importsNotUsedAsValues',
'jsx',
'jsxFactory',
'jsxFragmentFactory',
'useDefineForClassFields',
'importsNotUsedAsValues',
'jsxImportSource',
'preserveValueImports',
'target',
'useDefineForClassFields',
]
const compilerOptionsForFile: TSCompilerOptions = {}
if (loader === 'ts' || loader === 'tsx') {
Expand Down Expand Up @@ -130,6 +136,25 @@ export async function transformWithEsbuild(
tsconfigRaw,
} as ESBuildOptions

// esbuild uses tsconfig fields when both the normal options and tsconfig was set
// but we want to prioritize the normal options
if (
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
options &&
typeof resolvedOptions.tsconfigRaw === 'object' &&
resolvedOptions.tsconfigRaw.compilerOptions
) {
options.jsx && (resolvedOptions.tsconfigRaw.compilerOptions.jsx = undefined)
options.jsxFactory &&
(resolvedOptions.tsconfigRaw.compilerOptions.jsxFactory = undefined)
options.jsxFragment &&
(resolvedOptions.tsconfigRaw.compilerOptions.jsxFragmentFactory =
undefined)
options.jsxImportSource &&
(resolvedOptions.tsconfigRaw.compilerOptions.jsxImportSource = undefined)
options.target &&
(resolvedOptions.tsconfigRaw.compilerOptions.target = undefined)
}

delete resolvedOptions.include
delete resolvedOptions.exclude
delete resolvedOptions.jsxInject
Expand Down