1
1
import fs from 'fs'
2
2
import type { Plugin , ViteDevServer } from 'vite'
3
- import { createFilter } from 'vite'
4
- /* eslint-disable import/no-duplicates */
3
+ import { createFilter } from '@rollup/pluginutils'
5
4
import type {
6
5
SFCBlock ,
7
6
SFCScriptCompileOptions ,
8
7
SFCStyleCompileOptions ,
9
8
SFCTemplateCompileOptions
10
9
} from 'vue/compiler-sfc'
11
10
import type * as _compiler from 'vue/compiler-sfc'
12
- /* eslint-enable import/no-duplicates */
13
11
import { resolveCompiler } from './compiler'
14
12
import { parseVueRequest } from './utils/query'
15
13
import { getDescriptor , getSrcDescriptor } from './utils/descriptorCache'
@@ -34,32 +32,9 @@ export interface Options {
34
32
template ?: Partial < SFCTemplateCompileOptions >
35
33
style ?: Partial < SFCStyleCompileOptions >
36
34
37
- /**
38
- * Transform Vue SFCs into custom elements.
39
- * - `true`: all `*.vue` imports are converted into custom elements
40
- * - `string | RegExp`: matched files are converted into custom elements
41
- *
42
- * @default /\.ce\.vue$/
43
- */
44
- customElement ?: boolean | string | RegExp | ( string | RegExp ) [ ]
45
-
46
- /**
47
- * Enable Vue reactivity transform (experimental).
48
- * https://github.com/vuejs/core/tree/master/packages/reactivity-transform
49
- * - `true`: transform will be enabled for all vue,js(x),ts(x) files except
50
- * those inside node_modules
51
- * - `string | RegExp`: apply to vue + only matched files (will include
52
- * node_modules, so specify directories in necessary)
53
- * - `false`: disable in all cases
54
- *
55
- * @default false
56
- */
57
- reactivityTransform ?: boolean | string | RegExp | ( string | RegExp ) [ ]
58
-
59
- /**
60
- * Use custom compiler-sfc instance. Can be used to force a specific version.
61
- */
62
- compiler ?: typeof _compiler
35
+ // customElement?: boolean | string | RegExp | (string | RegExp)[]
36
+ // reactivityTransform?: boolean | string | RegExp | (string | RegExp)[]
37
+ // compiler?: typeof _compiler
63
38
}
64
39
65
40
export interface ResolvedOptions extends Options {
@@ -74,33 +49,21 @@ export interface ResolvedOptions extends Options {
74
49
export default function vuePlugin ( rawOptions : Options = { } ) : Plugin {
75
50
const {
76
51
include = / \. v u e $ / ,
77
- exclude,
78
- customElement = / \. c e \. v u e $ / ,
79
- reactivityTransform = false
52
+ exclude
53
+ // customElement = /\.ce\.vue$/,
54
+ // reactivityTransform = false
80
55
} = rawOptions
81
56
82
57
const filter = createFilter ( include , exclude )
83
58
84
- const customElementFilter =
85
- typeof customElement === 'boolean'
86
- ? ( ) => customElement
87
- : createFilter ( customElement )
88
-
89
- const refTransformFilter =
90
- reactivityTransform === false
91
- ? ( ) => false
92
- : reactivityTransform === true
93
- ? createFilter ( / \. ( j | t ) s x ? $ / , / n o d e _ m o d u l e s / )
94
- : createFilter ( reactivityTransform )
95
-
96
59
let options : ResolvedOptions = {
97
60
isProduction : process . env . NODE_ENV === 'production' ,
98
61
compiler : null as any , // to be set in buildStart
99
62
...rawOptions ,
100
63
include,
101
64
exclude,
102
- customElement,
103
- reactivityTransform,
65
+ // customElement,
66
+ // reactivityTransform,
104
67
root : process . cwd ( ) ,
105
68
sourceMap : true ,
106
69
cssDevSourcemap : false ,
@@ -117,25 +80,13 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
117
80
return handleHotUpdate ( ctx , options )
118
81
} ,
119
82
120
- config ( config ) {
121
- return {
122
- define : {
123
- __VUE_OPTIONS_API__ : config . define ?. __VUE_OPTIONS_API__ ?? true ,
124
- __VUE_PROD_DEVTOOLS__ : config . define ?. __VUE_PROD_DEVTOOLS__ ?? false
125
- } ,
126
- ssr : {
127
- external : [ 'vue' , '@vue/server-renderer' ]
128
- }
129
- }
130
- } ,
131
-
132
83
configResolved ( config ) {
133
84
options = {
134
85
...options ,
135
86
root : config . root ,
87
+ isProduction : config . isProduction ,
136
88
sourceMap : config . command === 'build' ? ! ! config . build . sourcemap : true ,
137
89
cssDevSourcemap : config . css ?. devSourcemap ?? false ,
138
- isProduction : config . isProduction ,
139
90
devToolsEnabled :
140
91
! ! config . define ! . __VUE_PROD_DEVTOOLS__ || ! config . isProduction
141
92
}
@@ -146,7 +97,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
146
97
} ,
147
98
148
99
buildStart ( ) {
149
- options . compiler = options . compiler || resolveCompiler ( options . root )
100
+ options . compiler = resolveCompiler ( options . root )
150
101
} ,
151
102
152
103
async resolveId ( id ) {
@@ -200,29 +151,22 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
200
151
return
201
152
}
202
153
if ( ! filter ( filename ) && ! query . vue ) {
203
- if (
204
- ! query . vue &&
205
- refTransformFilter ( filename ) &&
206
- options . compiler . shouldTransformRef ( code )
207
- ) {
208
- return options . compiler . transformRef ( code , {
209
- filename,
210
- sourceMap : true
211
- } )
212
- }
154
+ // if (
155
+ // !query.vue &&
156
+ // refTransformFilter(filename) &&
157
+ // options.compiler.shouldTransformRef(code)
158
+ // ) {
159
+ // return options.compiler.transformRef(code, {
160
+ // filename,
161
+ // sourceMap: true
162
+ // })
163
+ // }
213
164
return
214
165
}
215
166
216
167
if ( ! query . vue ) {
217
168
// main request
218
- return transformMain (
219
- code ,
220
- filename ,
221
- options ,
222
- this ,
223
- ssr ,
224
- customElementFilter ( filename )
225
- )
169
+ return transformMain ( code , filename , options , this , ssr )
226
170
} else {
227
171
// sub block request
228
172
const descriptor = query . src
0 commit comments