Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8a5ffc

Browse files
authored
fix(optimizer): enable experimentalDecorators by default (#13981)
1 parent844451c commitf8a5ffc

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

‎packages/vite/src/node/optimizer/index.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
import { transformWithEsbuild } from '../plugins/esbuild'
2828
import { ESBUILD_MODULES_TARGET } from '../constants'
2929
import { esbuildCjsExternalPlugin, esbuildDepPlugin } from './esbuildDepPlugin'
30-
import { scanImports } from './scan'
30+
import {resolveTsconfigRaw,scanImports } from './scan'
3131
import { createOptimizeDepsIncludeResolver, expandGlobIds } from './resolve'
3232
export {
3333
initDepsOptimizer,
@@ -713,8 +713,12 @@ async function prepareEsbuildOptimizerRun(
713713

714714
const optimizeDeps = getDepOptimizationConfig(config, ssr)
715715

716-
const { plugins: pluginsFromConfig = [], ...esbuildOptions } =
717-
optimizeDeps?.esbuildOptions ?? {}
716+
const {
717+
plugins: pluginsFromConfig = [],
718+
tsconfig,
719+
tsconfigRaw,
720+
...esbuildOptions
721+
} = optimizeDeps?.esbuildOptions ?? {}
718722

719723
await Promise.all(
720724
Object.keys(depsInfo).map(async (id) => {
@@ -806,6 +810,8 @@ async function prepareEsbuildOptimizerRun(
806810
metafile: true,
807811
plugins,
808812
charset: 'utf8',
813+
tsconfig,
814+
tsconfigRaw: resolveTsconfigRaw(tsconfig, tsconfigRaw),
809815
...esbuildOptions,
810816
supported: {
811817
'dynamic-import': true,

‎packages/vite/src/node/optimizer/scan.ts‎

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import fsp from 'node:fs/promises'
33
import path from 'node:path'
44
import { performance } from 'node:perf_hooks'
55
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'
713
import esbuild, { formatMessages, transform } from 'esbuild'
814
import colors from 'picocolors'
915
import type { ResolvedConfig } from '..'
@@ -224,16 +230,7 @@ async function prepareEsbuildScanner(
224230
logLevel: 'silent',
225231
plugins: [...plugins, plugin],
226232
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),
237234
...esbuildOptions,
238235
})
239236
}
@@ -666,3 +663,22 @@ function shouldExternalizeDep(resolvedId: string, rawId: string): boolean {
666663
function isScannable(id: string): boolean {
667664
return JS_TYPES_RE.test(id) || htmlTypesRE.test(id)
668665
}
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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp