From 91f581b99644119b68e586a0b642fff3811c8741 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 22 Sep 2021 18:20:26 -0400 Subject: [PATCH] fix: fix template options resolving for ts --- src/resolveScript.ts | 4 +--- src/templateLoader.ts | 4 +--- src/util.ts | 9 ++++++--- 3 files changed, 8 insertions(+), 9 deletions(-) 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'] }