1
- try {
2
- require . resolve ( '@vue/compiler-sfc' )
3
- } catch ( e ) {
4
- throw new Error (
5
- '@vitejs/plugin-vue requires @vue/compiler-sfc to be present in the dependency ' +
6
- 'tree.'
7
- )
8
- }
9
-
10
1
import fs from 'fs'
11
2
import { Plugin , ViteDevServer } from 'vite'
12
3
import { createFilter } from '@rollup/pluginutils'
13
4
import {
14
5
SFCBlock ,
15
6
SFCScriptCompileOptions ,
16
7
SFCStyleCompileOptions ,
17
- SFCTemplateCompileOptions ,
18
- shouldTransformRef ,
19
- transformRef
8
+ SFCTemplateCompileOptions
20
9
} from '@vue/compiler-sfc'
10
+ import { compiler } from './compiler'
21
11
import { parseVueRequest } from './utils/query'
22
12
import { getDescriptor } from './utils/descriptorCache'
23
13
import { getResolvedScript } from './script'
@@ -27,13 +17,6 @@ import { transformTemplateAsModule } from './template'
27
17
import { transformStyle } from './style'
28
18
import { EXPORT_HELPER_ID , helperCode } from './helper'
29
19
30
- // extend the descriptor so we can store the scopeId on it
31
- declare module '@vue/compiler-sfc' {
32
- interface SFCDescriptor {
33
- id : string
34
- }
35
- }
36
-
37
20
export { parseVueRequest , VueQuery } from './utils/query'
38
21
39
22
export interface Options {
@@ -108,7 +91,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
108
91
: createFilter ( refTransform )
109
92
110
93
// compat for older verisons
111
- const canUseRefTransform = typeof shouldTransformRef === 'function'
94
+ const canUseRefTransform = typeof compiler . shouldTransformRef === 'function'
112
95
113
96
let options : ResolvedOptions = {
114
97
isProduction : process . env . NODE_ENV === 'production' ,
@@ -209,8 +192,8 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
209
192
if ( ! query . vue && refTransformFilter ( filename ) ) {
210
193
if ( ! canUseRefTransform ) {
211
194
this . warn ( 'refTransform requires @vue/compiler-sfc@^3.2.5.' )
212
- } else if ( shouldTransformRef ( code ) ) {
213
- return transformRef ( code , {
195
+ } else if ( compiler . shouldTransformRef ( code ) ) {
196
+ return compiler . transformRef ( code , {
214
197
filename,
215
198
sourceMap : true
216
199
} )
0 commit comments