-
-
Notifications
You must be signed in to change notification settings - Fork 351
/
element-ui.ts
71 lines (65 loc) · 1.66 KB
/
element-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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type {
ComponentResolver,
SideEffectsInfo,
} from '../../types'
import { kebabCase } from '../utils'
export interface ElementUiResolverOptions {
/**
* import style css or sass with components
*
* @default 'css'
*/
importStyle?: boolean | 'css' | 'sass'
/**
* exclude component name, if match do not resolve the name
*/
exclude?: RegExp
}
function getSideEffects(
partialName: string,
options: ElementUiResolverOptions,
): SideEffectsInfo | undefined {
const { importStyle = 'css' } = options
if (!importStyle)
return
if (importStyle === 'sass') {
return [
'element-ui/packages/theme-chalk/src/base.scss',
`element-ui/packages/theme-chalk/src/${partialName}.scss`,
]
}
else {
return [
'element-ui/lib/theme-chalk/base.css',
`element-ui/lib/theme-chalk/${partialName}.css`,
]
}
}
/**
* Resolver for Element-UI
* @link https://element.eleme.cn/#/zh-CN
* @version @element-ui ^2.15.3, @vue ^2.6.14
* @author @nabaonan
*/
export function ElementUiResolver(options: ElementUiResolverOptions = {}): ComponentResolver {
return {
type: 'component',
resolve: (name: string) => {
if (options.exclude && name.match(options.exclude))
return
if (/^El[A-Z]/.test(name)) {
const compName = name.slice(2)
const partialName = kebabCase(compName)
if (partialName === 'collapse-transition') {
return {
from: `element-ui/lib/transitions/${partialName}`,
}
}
return {
from: `element-ui/lib/${partialName}`,
sideEffects: getSideEffects(partialName, options),
}
}
},
}
}