-
-
Notifications
You must be signed in to change notification settings - Fork 354
/
tdesign.ts
59 lines (50 loc) · 1.41 KB
/
tdesign.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
54
55
56
57
58
59
import type { FilterPattern } from '@rollup/pluginutils'
import type { ComponentResolver } from '../../types'
import { isExclude } from '../utils'
export interface TDesignResolverOptions {
/**
* select the specified library
* @default 'vue'
*/
library?: 'vue' | 'vue-next' | 'react' | 'mobile-vue' | 'mobile-react'
/**
* resolve `tdesign-icons'
* @default false
*/
resolveIcons?: boolean
/**
* whether to import ESM version
* @default false
*/
esm?: boolean
/**
* exclude component name, if match do not resolve the name
*
*/
exclude?: FilterPattern
}
export function TDesignResolver(options: TDesignResolverOptions = {}): ComponentResolver {
const pluginList = ['DialogPlugin', 'LoadingPlugin', 'MessagePlugin', 'NotifyPlugin']
return {
type: 'component',
resolve: (name: string) => {
const { library = 'vue', exclude } = options
const importFrom = options.esm ? '/esm' : ''
if (isExclude(name, exclude))
return
if (options.resolveIcons && name.match(/[a-z]Icon$/)) {
return {
name,
from: `tdesign-icons-${library}${importFrom}`,
}
}
if (name.match(/^T[A-Z]/) || pluginList.includes(name)) {
const importName = name.match(/^T[A-Z]/) ? name.slice(1) : name
return {
name: importName,
from: `tdesign-${library}${importFrom}`,
}
}
},
}
}