Skip to content

Commit b038ba9

Browse files
authored
feat: add Varlet UI resolver (#63)
1 parent 2e178cf commit b038ba9

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.DS_Store
33
dist
4+
.idea

src/resolvers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './vant'
55
export * from './vuetify'
66
export * from './vueuse'
77
export * from './naive-ui'
8+
export * from './varlet-ui'

src/resolvers/varlet-ui.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { ComponentResolver } from '../types'
2+
import { kebabCase } from '../utils'
3+
4+
export interface VarletUIResolverOptions {
5+
/**
6+
* import css along with components
7+
*
8+
* @default true
9+
*/
10+
importCss?: boolean
11+
/**
12+
* import less along with components
13+
*
14+
* @default false
15+
*/
16+
importLess?: boolean
17+
}
18+
19+
/**
20+
* Resolver for VarletUI
21+
*
22+
* @link https://github.com/haoziqaq/varlet
23+
*/
24+
export const VarletUIResolver = (options: VarletUIResolverOptions = {}): ComponentResolver => (name: string) => {
25+
const {
26+
importCss = true,
27+
importLess
28+
} = options
29+
if (name.startsWith('Var')) {
30+
const partialName = name.slice(3)
31+
return {
32+
importName: partialName,
33+
path: '@varlet/ui/es',
34+
sideEffects: importLess
35+
? `@varlet/ui/es/${kebabCase(partialName)}/style/less.js`
36+
: importCss
37+
? `@varlet/ui/es/${kebabCase(partialName)}/style`
38+
: undefined
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)