-
-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathindex.ts
46 lines (37 loc) · 1.08 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
44
45
46
import type { Plugin } from 'vite'
import { Options } from './types'
import { Context } from './context'
import { VueTransformer } from './transforms/vue'
import { parseId, resolveOptions } from './utils'
const defaultOptions: Required<Options> = {
dirs: 'src/components',
extensions: 'vue',
deep: true,
directoryAsNamespace: false,
globalNamespaces: [],
libraries: [],
customLoaderMatcher: () => false,
customComponentResolvers: [],
}
function VitePluginComponents(options: Options = {}): Plugin {
const ctx: Context = new Context(resolveOptions(options, defaultOptions))
const transformer = [
VueTransformer(ctx),
]
return {
name: 'vite-plugin-components',
configResolved(config) {
ctx.viteConfig = config
},
transform(code, id) {
const { path, query } = parseId(id)
for (const trans of transformer)
code = trans(code, id, path, query)
return code
},
}
}
export * from './helpers/libraryResolver'
export * from './types'
export { camelCase, pascalCase, kebabCase } from './utils'
export default VitePluginComponents