-
-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathvant.ts
49 lines (41 loc) · 1.2 KB
/
vant.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
import type { ComponentResolver, SideEffectsInfo } from '../../types'
import { isSSR, kebabCase } from '../utils'
const moduleType = isSSR ? 'lib' : 'es'
export interface VantResolverOptions {
/**
* import style css or less along with components
*
* @default true
*/
importStyle?: boolean | 'css' | 'less'
}
function getSideEffects(dirName: string, options: VantResolverOptions): SideEffectsInfo | undefined {
const { importStyle = true } = options
if (!importStyle || isSSR)
return
if (importStyle === 'less')
return `vant/${moduleType}/${dirName}/style/less`
if (importStyle === 'css')
return `vant/${moduleType}/${dirName}/style/index`
return `vant/${moduleType}/${dirName}/style/index`
}
/**
* Resolver for Vant
*
* @link https://github.com/youzan/vant
*/
export function VantResolver(options: VantResolverOptions = {}): ComponentResolver {
return {
type: 'component',
resolve: (name: string) => {
if (name.startsWith('Van')) {
const partialName = name.slice(3)
return {
name: partialName,
from: `vant/${moduleType}`,
sideEffects: getSideEffects(kebabCase(partialName), options),
}
}
},
}
}