diff --git a/src/resolveScript.ts b/src/resolveScript.ts index 0d8eea655..51b0c5aa7 100644 --- a/src/resolveScript.ts +++ b/src/resolveScript.ts @@ -66,9 +66,7 @@ export function resolveScript( compiler: templateCompiler, compilerOptions: { ...options.compilerOptions, - ...(options.enableTsInTemplate - ? resolveTemplateTSOptions(descriptor, options.compilerOptions) - : null), + ...resolveTemplateTSOptions(descriptor, options), }, transformAssetUrls: options.transformAssetUrls || true, }, diff --git a/src/templateLoader.ts b/src/templateLoader.ts index 00db6cbe6..2129ad95e 100644 --- a/src/templateLoader.ts +++ b/src/templateLoader.ts @@ -63,9 +63,7 @@ const TemplateLoader: webpack.loader.Loader = function (source, inMap) { ...options.compilerOptions, scopeId: query.scoped ? `data-v-${scopeId}` : undefined, bindingMetadata: script ? script.bindings : undefined, - ...(options.enableTsInTemplate - ? resolveTemplateTSOptions(descriptor, options.compilerOptions) - : null), + ...resolveTemplateTSOptions(descriptor, options), }, transformAssetUrls: options.transformAssetUrls || true, }) diff --git a/src/util.ts b/src/util.ts index a6ce1be30..1387982c5 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,12 +1,15 @@ import { SFCDescriptor, CompilerOptions } from '@vue/compiler-sfc' +import { VueLoaderOptions } from '.' export function resolveTemplateTSOptions( descriptor: SFCDescriptor, - options: CompilerOptions | null | undefined -): CompilerOptions { + options: VueLoaderOptions +): CompilerOptions | null { + if (options.enableTsInTemplate === false) return null + const lang = descriptor.script?.lang || descriptor.scriptSetup?.lang const isTS = !!(lang && /tsx?$/.test(lang)) - let expressionPlugins = (options && options.expressionPlugins) || [] + let expressionPlugins = options?.compilerOptions?.expressionPlugins || [] if (isTS && !expressionPlugins.includes('typescript')) { expressionPlugins = [...expressionPlugins, 'typescript'] }