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
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"conventional-changelog-cli": "^2.2.2",
"esbuild": "^0.15.9",
"esbuild": "^0.15.11",
"eslint": "^8.28.0",
"eslint-define-config": "^1.12.0",
"eslint-plugin-import": "^2.26.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
"dependencies": {
"esbuild": "^0.15.9",
"esbuild": "^0.15.11",
"postcss": "^8.4.19",
"resolve": "^1.22.1",
"rollup": "~3.3.0"
Expand Down
37 changes: 30 additions & 7 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
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',
'preserveValueImports'
'jsxImportSource',
'preserveValueImports',
'target',
'useDefineForClassFields'
]
const compilerOptionsForFile: TSCompilerOptions = {}
if (loader === 'ts' || loader === 'tsx') {
Expand Down Expand Up @@ -130,6 +136,23 @@ export async function transformWithEsbuild(
tsconfigRaw
} as ESBuildOptions

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
Loading