-
-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathindex.ts
43 lines (38 loc) · 1.23 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { Plugin } from 'vite'
import { Options, Transformer } from './types'
import { Context } from './context'
import { parseId } from './utils'
import { Vue3Transformer } from './transforms/vue3'
import { Vue2Transformer } from './transforms/vue2'
function VitePluginComponents(options: Options = {}): Plugin {
let ctx: Context
let transformer: Transformer
return {
name: 'vite-plugin-components',
enforce: 'post',
configResolved(config) {
if (config.plugins.find(i => i.name === 'vite-plugin-vue2'))
options.transformer = options.transformer || 'vue2'
ctx = new Context(options, config)
transformer = ctx.options.transformer === 'vue2'
? Vue2Transformer(ctx)
: Vue3Transformer(ctx)
if (options.globalComponentsDeclaration) {
ctx.searchGlob()
ctx.generateDeclaration()
}
},
configureServer(server) {
ctx.setServer(server)
},
transform(code, id) {
const { path, query } = parseId(id)
return transformer(code, id, path, query)
},
}
}
export * from './helpers/libraryResolver'
export * from './types'
export * from './resolvers'
export { camelCase, pascalCase, kebabCase } from './utils'
export default VitePluginComponents