@@ -17,6 +17,8 @@ import {
17
17
SFCTemplateCompileOptions ,
18
18
SFCTemplateCompileResults ,
19
19
SFCAsyncStyleCompileOptions ,
20
+ TemplateCompiler ,
21
+ CompilerOptions ,
20
22
} from '@vue/compiler-sfc'
21
23
import fs from 'fs'
22
24
import createDebugger from 'debug'
@@ -28,6 +30,8 @@ import { createFilter } from 'rollup-pluginutils'
28
30
29
31
const debug = createDebugger ( 'rollup-plugin-vue' )
30
32
33
+ type TemplateCompilerOptions = [ TemplateCompiler , CompilerOptions ]
34
+
31
35
export interface Options {
32
36
include : string | RegExp | ( string | RegExp ) [ ]
33
37
exclude : string | RegExp | ( string | RegExp ) [ ]
@@ -44,6 +48,7 @@ export interface Options {
44
48
compiler ?: SFCTemplateCompileOptions [ 'compiler' ]
45
49
compilerOptions ?: SFCTemplateCompileOptions [ 'compilerOptions' ]
46
50
transformAssetUrls ?: SFCTemplateCompileOptions [ 'transformAssetUrls' ]
51
+ templateCompilers ?: Record < string , TemplateCompilerOptions >
47
52
48
53
// sfc style options
49
54
postcssOptions ?: SFCAsyncStyleCompileOptions [ 'postcssOptions' ]
@@ -139,6 +144,25 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
139
144
const descriptor = getDescriptor ( query . filename )
140
145
const hasScoped = descriptor . styles . some ( ( s ) => s . scoped )
141
146
if ( query . type === 'template' ) {
147
+ const compilerKey = query . compiler
148
+ let compiler = options . compiler
149
+ let compilerOptions = options . compilerOptions || { }
150
+ if ( compilerKey ) {
151
+ if (
152
+ options . templateCompilers &&
153
+ options . templateCompilers [ compilerKey ]
154
+ ) {
155
+ ; [ compiler , compilerOptions ] = options . templateCompilers [
156
+ compilerKey
157
+ ]
158
+ } else {
159
+ this . error ( {
160
+ id : query . filename ,
161
+ message : `The "${ compilerKey } " compiler not found.Please add "templateCompilers" options.` ,
162
+ } )
163
+ }
164
+ }
165
+
142
166
debug ( `transform(${ id } )` )
143
167
const block = descriptor . template !
144
168
const result = compileTemplate ( {
@@ -147,10 +171,10 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
147
171
inMap : query . src ? undefined : block . map ,
148
172
preprocessLang : block . lang ,
149
173
preprocessCustomRequire : options . preprocessCustomRequire ,
150
- compiler : options . compiler ,
174
+ compiler,
151
175
ssr : isServer ,
152
176
compilerOptions : {
153
- ...options . compilerOptions ,
177
+ ...compilerOptions ,
154
178
scopeId : hasScoped ? `data-v-${ query . id } ` : undefined ,
155
179
} ,
156
180
transformAssetUrls : options . transformAssetUrls ,
@@ -292,6 +316,7 @@ type Query =
292
316
type : 'template'
293
317
id ?: string
294
318
src ?: true
319
+ compiler ?: string
295
320
}
296
321
| {
297
322
filename : string
0 commit comments