6
6
SFCScriptCompileOptions ,
7
7
SFCStyleCompileOptions ,
8
8
SFCTemplateCompileOptions
9
- } from '@vue/compiler-sfc'
10
- import { compiler } from './compiler'
9
+ } from 'vue/compiler-sfc'
10
+ import * as _compiler from 'vue/compiler-sfc'
11
+ import { resolveCompiler } from './compiler'
11
12
import { parseVueRequest } from './utils/query'
12
13
import { getDescriptor , getSrcDescriptor } from './utils/descriptorCache'
13
14
import { getResolvedScript } from './script'
@@ -25,7 +26,7 @@ export interface Options {
25
26
26
27
isProduction ?: boolean
27
28
28
- // options to pass on to @ vue /compiler-sfc
29
+ // options to pass on to vue/compiler-sfc
29
30
script ?: Partial < SFCScriptCompileOptions >
30
31
template ?: Partial < SFCTemplateCompileOptions >
31
32
style ?: Partial < SFCStyleCompileOptions >
@@ -60,9 +61,15 @@ export interface Options {
60
61
* @deprecated the plugin now auto-detects whether it's being invoked for ssr.
61
62
*/
62
63
ssr ?: boolean
64
+
65
+ /**
66
+ * Use custom compiler-sfc instance. Can be used to force a specific version.
67
+ */
68
+ compiler ?: typeof _compiler
63
69
}
64
70
65
71
export interface ResolvedOptions extends Options {
72
+ compiler : typeof _compiler
66
73
root : string
67
74
sourceMap : boolean
68
75
devServer ?: ViteDevServer
@@ -90,9 +97,6 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
90
97
? createFilter ( / \. ( j | t ) s x ? $ / , / n o d e _ m o d u l e s / )
91
98
: createFilter ( refTransform )
92
99
93
- // compat for older versions
94
- const canUseRefTransform = typeof compiler . shouldTransformRef === 'function'
95
-
96
100
let options : ResolvedOptions = {
97
101
isProduction : process . env . NODE_ENV === 'production' ,
98
102
...rawOptions ,
@@ -101,7 +105,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
101
105
customElement,
102
106
refTransform,
103
107
root : process . cwd ( ) ,
104
- sourceMap : true
108
+ sourceMap : true ,
109
+ compiler : null as any // to be set in configResolved
105
110
}
106
111
107
112
// Temporal handling for 2.7 breaking change
@@ -122,7 +127,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
122
127
return handleHotUpdate ( ctx , options )
123
128
} ,
124
129
125
- config ( config ) {
130
+ config ( ) {
126
131
return {
127
132
define : {
128
133
__VUE_OPTIONS_API__ : true ,
@@ -139,7 +144,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
139
144
...options ,
140
145
root : config . root ,
141
146
sourceMap : config . command === 'build' ? ! ! config . build . sourcemap : true ,
142
- isProduction : config . isProduction
147
+ isProduction : config . isProduction ,
148
+ compiler : options . compiler || resolveCompiler ( config . root )
143
149
}
144
150
} ,
145
151
@@ -198,15 +204,15 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
198
204
return
199
205
}
200
206
if ( ! filter ( filename ) && ! query . vue ) {
201
- if ( ! query . vue && refTransformFilter ( filename ) ) {
202
- if ( ! canUseRefTransform ) {
203
- this . warn ( 'refTransform requires @vue/compiler-sfc@^3.2.5.' )
204
- } else if ( compiler . shouldTransformRef ( code ) ) {
205
- return compiler . transformRef ( code , {
206
- filename ,
207
- sourceMap : true
208
- } )
209
- }
207
+ if (
208
+ ! query . vue &&
209
+ refTransformFilter ( filename ) &&
210
+ options . compiler . shouldTransformRef ( code )
211
+ ) {
212
+ return options . compiler . transformRef ( code , {
213
+ filename ,
214
+ sourceMap : true
215
+ } )
210
216
}
211
217
return
212
218
}
0 commit comments