File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -202,6 +202,7 @@ Supported Resolvers:
202
202
- [ View UI] ( https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/view-ui.ts )
203
203
- [ Vuetify] ( https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vuetify.ts )
204
204
- [ VueUse Components] ( https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse.ts )
205
+ - [ VueUse Directives] ( https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse-directive.ts )
205
206
- [ Dev UI] ( https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/devui.ts )
206
207
207
208
``` ts
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export * from './veui'
12
12
export * from './view-ui'
13
13
export * from './vuetify'
14
14
export * from './vueuse'
15
+ export * from './vueuse-directive'
15
16
export * from './quasar'
16
17
export * from './devui'
17
18
export * from './arco'
Original file line number Diff line number Diff line change
1
+ import { readFileSync } from 'fs'
2
+ import { resolveModule } from 'local-pkg'
3
+ import type { ComponentResolver } from '../../types'
4
+
5
+ let directives : string [ ] | undefined
6
+
7
+ /**
8
+ * Resolver for VueUse
9
+ *
10
+ * @link https://github.com/vueuse/vueuse
11
+ */
12
+ export function VueUseDirectiveResolver ( ) : ComponentResolver {
13
+ return {
14
+ type : 'directive' ,
15
+ resolve : ( name : string ) => {
16
+ if ( ! directives ) {
17
+ let indexesJson : any
18
+ try {
19
+ const corePath = resolveModule ( '@vueuse/core' ) || process . cwd ( )
20
+ const path = resolveModule ( '@vueuse/core/indexes.json' )
21
+ || resolveModule ( '@vueuse/metadata/index.json' )
22
+ || resolveModule ( '@vueuse/metadata/index.json' , { paths : [ corePath ] } )
23
+ indexesJson = JSON . parse ( readFileSync ( path ! , 'utf-8' ) )
24
+ directives = indexesJson
25
+ . functions
26
+ . filter ( ( i : any ) => i . directive && i . name )
27
+ . map ( ( { name } : any ) => name [ 0 ] . toUpperCase ( ) + name . slice ( 1 ) )
28
+ }
29
+ catch ( error ) {
30
+ console . error ( error )
31
+ throw new Error ( '[vue-components] failed to load @vueuse/core, have you installed it?' )
32
+ }
33
+ }
34
+
35
+ if ( directives && directives . includes ( name ) )
36
+ return { name : `v${ name } ` , as : name , from : '@vueuse/components' }
37
+ } ,
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments