@@ -3,7 +3,13 @@ import fsp from 'node:fs/promises'
3
3
import path from 'node:path'
4
4
import { performance } from 'node:perf_hooks'
5
5
import glob from 'fast-glob'
6
- import type { BuildContext , Loader , OnLoadResult , Plugin } from 'esbuild'
6
+ import type {
7
+ BuildContext ,
8
+ BuildOptions ,
9
+ Loader ,
10
+ OnLoadResult ,
11
+ Plugin ,
12
+ } from 'esbuild'
7
13
import esbuild , { formatMessages , transform } from 'esbuild'
8
14
import colors from 'picocolors'
9
15
import type { ResolvedConfig } from '..'
@@ -224,16 +230,7 @@ async function prepareEsbuildScanner(
224
230
logLevel : 'silent' ,
225
231
plugins : [ ...plugins , plugin ] ,
226
232
tsconfig,
227
- tsconfigRaw :
228
- tsconfig || typeof tsconfigRaw === 'string'
229
- ? tsconfigRaw
230
- : {
231
- ...tsconfigRaw ,
232
- compilerOptions : {
233
- experimentalDecorators : true ,
234
- ...tsconfigRaw ?. compilerOptions ,
235
- } ,
236
- } ,
233
+ tsconfigRaw : resolveTsconfigRaw ( tsconfig , tsconfigRaw ) ,
237
234
...esbuildOptions ,
238
235
} )
239
236
}
@@ -666,3 +663,22 @@ function shouldExternalizeDep(resolvedId: string, rawId: string): boolean {
666
663
function isScannable ( id : string ) : boolean {
667
664
return JS_TYPES_RE . test ( id ) || htmlTypesRE . test ( id )
668
665
}
666
+
667
+ // esbuild v0.18 only transforms decorators when `experimentalDecorators` is set to `true`.
668
+ // To preserve compat with the esbuild breaking change, we set `experimentalDecorators` to
669
+ // `true` by default if it's unset.
670
+ // TODO: Remove this in Vite 5 and check https://github.com/vitejs/vite/pull/13805#issuecomment-1633612320
671
+ export function resolveTsconfigRaw (
672
+ tsconfig : string | undefined ,
673
+ tsconfigRaw : BuildOptions [ 'tsconfigRaw' ] ,
674
+ ) : BuildOptions [ 'tsconfigRaw' ] {
675
+ return tsconfig || typeof tsconfigRaw === 'string'
676
+ ? tsconfigRaw
677
+ : {
678
+ ...tsconfigRaw ,
679
+ compilerOptions : {
680
+ experimentalDecorators : true ,
681
+ ...tsconfigRaw ?. compilerOptions ,
682
+ } ,
683
+ }
684
+ }
0 commit comments