@@ -30,7 +30,7 @@ import { createFilter } from 'rollup-pluginutils'
30
30
31
31
const debug = createDebugger ( 'rollup-plugin-vue' )
32
32
33
- type TemplateCompilerOptions = [ TemplateCompiler , CompilerOptions ]
33
+ type TemplateCompilers = TemplateCompiler | [ TemplateCompiler , CompilerOptions ]
34
34
35
35
export interface Options {
36
36
include : string | RegExp | ( string | RegExp ) [ ]
@@ -48,7 +48,7 @@ export interface Options {
48
48
compiler ?: SFCTemplateCompileOptions [ 'compiler' ]
49
49
compilerOptions ?: SFCTemplateCompileOptions [ 'compilerOptions' ]
50
50
transformAssetUrls ?: SFCTemplateCompileOptions [ 'transformAssetUrls' ]
51
- templateCompilers ?: Record < string , TemplateCompilerOptions >
51
+ templateCompilers ?: Record < string , TemplateCompilers >
52
52
53
53
// sfc style options
54
54
postcssOptions ?: SFCAsyncStyleCompileOptions [ 'postcssOptions' ]
@@ -140,25 +140,34 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
140
140
const query = parseVuePartRequest ( id )
141
141
if ( query . vue ) {
142
142
if ( ! query . src && ! filter ( query . filename ) ) return null
143
-
144
143
const descriptor = getDescriptor ( query . filename )
145
144
const hasScoped = descriptor . styles . some ( ( s ) => s . scoped )
146
145
if ( query . type === 'template' ) {
147
146
const compilerKey = query . compiler
148
147
let compiler = options . compiler
149
148
let compilerOptions = options . compilerOptions || { }
150
149
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
+ }
158
167
} else {
159
168
this . error ( {
160
169
id : query . filename ,
161
- message : `The " ${ compilerKey } " compiler not found.Please add "templateCompilers" options .` ,
170
+ message : `Please ensure custom template compiler attribute .` ,
162
171
} )
163
172
}
164
173
}
0 commit comments