Skip to content

Commit

Permalink
fix: fix template options resolving for ts
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 22, 2021
1 parent 1666885 commit 91f581b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/resolveScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
4 changes: 1 addition & 3 deletions src/templateLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
9 changes: 6 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -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']
}
Expand Down

0 comments on commit 91f581b

Please sign in to comment.