-
-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathvarlet-ui.ts
53 lines (47 loc) · 1.2 KB
/
varlet-ui.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
47
48
49
50
51
52
53
import { ComponentResolver } from '../../types'
import { kebabCase } from '../utils'
export interface VarletUIResolverOptions {
/**
* import style along with components
*
* @default 'css'
*/
importStyle?: boolean | 'css' | 'less'
/**
* @deprecated use `importStyle: 'css'` instead
*/
importCss?: boolean
/**
* @deprecated use `importStyle: 'less'` instead
*/
importLess?: boolean
}
/**
* Resolver for VarletUI
*
* @link https://github.com/haoziqaq/varlet
*/
export function VarletUIResolver(options: VarletUIResolverOptions = {}): ComponentResolver {
return (name: string) => {
const {
importStyle = 'css',
importCss = true,
importLess,
} = options
if (name.startsWith('Var')) {
const partialName = name.slice(3)
const sideEffects = []
if (importStyle || importCss) {
if (importStyle === 'less' || importLess)
sideEffects.push(`@varlet/ui/es/${kebabCase(partialName)}/style/less.js`)
else
sideEffects.push(`@varlet/ui/es/${kebabCase(partialName)}/style`)
}
return {
importName: `_${partialName}Component`,
path: '@varlet/ui',
sideEffects,
}
}
}
}