Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 2180c52

Browse files
committed
fix: fix some error
1 parent 65b70dc commit 2180c52

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/index.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { createFilter } from 'rollup-pluginutils'
3030

3131
const debug = createDebugger('rollup-plugin-vue')
3232

33-
type TemplateCompilerOptions = [TemplateCompiler, CompilerOptions]
33+
type TemplateCompilers = TemplateCompiler | [TemplateCompiler, CompilerOptions]
3434

3535
export interface Options {
3636
include: string | RegExp | (string | RegExp)[]
@@ -48,7 +48,7 @@ export interface Options {
4848
compiler?: SFCTemplateCompileOptions['compiler']
4949
compilerOptions?: SFCTemplateCompileOptions['compilerOptions']
5050
transformAssetUrls?: SFCTemplateCompileOptions['transformAssetUrls']
51-
templateCompilers?: Record<string, TemplateCompilerOptions>
51+
templateCompilers?: Record<string, TemplateCompilers>
5252

5353
// sfc style options
5454
postcssOptions?: SFCAsyncStyleCompileOptions['postcssOptions']
@@ -140,25 +140,34 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
140140
const query = parseVuePartRequest(id)
141141
if (query.vue) {
142142
if (!query.src && !filter(query.filename)) return null
143-
144143
const descriptor = getDescriptor(query.filename)
145144
const hasScoped = descriptor.styles.some((s) => s.scoped)
146145
if (query.type === 'template') {
147146
const compilerKey = query.compiler
148147
let compiler = options.compiler
149148
let compilerOptions = options.compilerOptions || {}
150149
if (compilerKey) {
151-
if (
152-
options.templateCompilers &&
153-
options.templateCompilers[compilerKey]
154-
) {
155-
;[compiler, compilerOptions] = options.templateCompilers[
156-
compilerKey
157-
]
150+
if (typeof compilerKey === 'string') {
151+
if (
152+
options.templateCompilers &&
153+
options.templateCompilers[compilerKey]
154+
) {
155+
const compilers = options.templateCompilers[compilerKey]
156+
if (Array.isArray(compilers)) {
157+
;[compiler, compilerOptions] = compilers
158+
} else {
159+
compiler = compilers
160+
}
161+
} else {
162+
this.error({
163+
id: query.filename,
164+
message: `The "${compilerKey}" compiler not found.Please add "templateCompilers" options.`,
165+
})
166+
}
158167
} else {
159168
this.error({
160169
id: query.filename,
161-
message: `The "${compilerKey}" compiler not found.Please add "templateCompilers" options.`,
170+
message: `Please ensure custom template compiler attribute.`,
162171
})
163172
}
164173
}

0 commit comments

Comments
 (0)