Skip to content

Commit 62bc418

Browse files
authored
feat: add idux resolver (#121)
1 parent f545473 commit 62bc418

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ Supported Resolvers:
132132
- [Ant Design Vue](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/antdv.ts)
133133
- [Element Plus](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/element-plus.ts)
134134
- [Headless UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/headless-ui.ts)
135+
- [IDux](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/idux.ts)
135136
- [Naive UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/naive-ui.ts)
136137
- [Prime Vue](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/prime-vue.ts)
137138
- [Vant](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/vant.ts)

src/resolvers/idux.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { ComponentResolver } from "../types"
2+
import { kebabCase } from "../utils"
3+
4+
export interface IduxResolverOptions {
5+
/**
6+
* import style along with components
7+
*/
8+
importStyle?: 'css' | 'less'
9+
}
10+
11+
/**
12+
* Resolver for `@idux/cdk` and `@idux/components`
13+
*
14+
* @link https://idux.site
15+
*/
16+
export function IduxResolver(options: IduxResolverOptions = {}): ComponentResolver {
17+
return (name: string) => {
18+
if (name.match(/^Ix[A-Z]/)) {
19+
const { importStyle } = options
20+
const compName = name.slice(2)
21+
const kebabCaseName = kebabCase(compName)
22+
const isCdk = cdkNames.includes(kebabCaseName)
23+
const packageName = isCdk ? 'cdk' : 'components'
24+
const dirname = getDirname(kebabCaseName)
25+
const path = `@idux/${packageName}/${dirname}`
26+
const sideEffects = isCdk || !importStyle ? undefined : `${path}/style/${importStyle === 'css' ? 'css' : 'index'}`
27+
28+
return { importName: name, path, sideEffects }
29+
}
30+
}
31+
}
32+
33+
const cdkNames = ['portal', 'resizable', 'virtual-list']
34+
const kebabCaseDirnames = [
35+
'virtual-list',
36+
'auto-complete',
37+
'back-top',
38+
'date-picker',
39+
'input-number',
40+
'time-picker',
41+
'tree-select',
42+
]
43+
44+
function getDirname(compName: string): string {
45+
const dirname = kebabCaseDirnames.find(name => compName.startsWith(name))
46+
if (dirname) {
47+
return dirname
48+
}
49+
50+
const [first] = compName.split('-')
51+
if (first === 'row' || first === 'col') {
52+
return 'grid'
53+
}
54+
return first
55+
}

src/resolvers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from './antdv'
22
export * from './element-plus'
33
export * from './element-ui'
44
export * from './headless-ui'
5+
export * from './idux'
56
export * from './naive-ui'
67
export * from './prime-vue'
78
export * from './vant'

0 commit comments

Comments
 (0)