diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index 3c592cec499de5..c762b6b584cf8f 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -205,8 +205,11 @@ async function prepareEsbuildScanner( const plugin = esbuildScanPlugin(config, container, deps, missing, entries) - const { plugins = [], ...esbuildOptions } = - config.optimizeDeps?.esbuildOptions ?? {} + const { + plugins = [], + tsconfigRaw, + ...esbuildOptions + } = config.optimizeDeps?.esbuildOptions ?? {} return await esbuild.context({ absWorkingDir: process.cwd(), @@ -219,6 +222,16 @@ async function prepareEsbuildScanner( format: 'esm', logLevel: 'silent', plugins: [...plugins, plugin], + tsconfigRaw: + typeof tsconfigRaw === 'string' + ? tsconfigRaw + : { + ...tsconfigRaw, + compilerOptions: { + experimentalDecorators: true, + ...tsconfigRaw?.compilerOptions, + }, + }, ...esbuildOptions, }) } diff --git a/playground/tsconfig-json/src/decorator.ts b/playground/tsconfig-json/src/decorator.ts index 27a5027cb23f17..2dc056ec09c809 100644 --- a/playground/tsconfig-json/src/decorator.ts +++ b/playground/tsconfig-json/src/decorator.ts @@ -4,5 +4,8 @@ function first() { export class Foo { @first() - method() {} + // @ts-expect-error we intentionally not enable `experimentalDecorators` to test esbuild compat + method(@first test: string) { + return test + } } diff --git a/playground/tsconfig-json/src/main.ts b/playground/tsconfig-json/src/main.ts index 6ae1fe03b7d023..bec5c6bcc2729d 100644 --- a/playground/tsconfig-json/src/main.ts +++ b/playground/tsconfig-json/src/main.ts @@ -1,6 +1,7 @@ // @ts-nocheck import '../nested/main' import '../nested-with-extends/main' +import './decorator' // eslint-disable-next-line @typescript-eslint/consistent-type-imports import { MainTypeOnlyClass } from './not-used-type'