Skip to content

Commit c6dbe69

Browse files
authored
feat: add TDesign resolver (unplugin#267)
1 parent 86dfdc8 commit c6dbe69

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/core/resolvers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export * from './vueuse'
1414
export * from './quasar'
1515
export * from './devui'
1616
export * from './arco'
17+
export * from './tdesign'

src/core/resolvers/tdesign.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { ComponentResolver, SideEffectsInfo } from '../../types'
2+
import { kebabCase } from '../utils'
3+
4+
export interface TDesignResolverOptions {
5+
/**
6+
* import style along with components
7+
* @default 'css'
8+
*/
9+
importStyle?: boolean | 'css' | 'less'
10+
11+
/**
12+
* select the specified library
13+
* @default 'vue'
14+
*/
15+
library?: 'vue' | 'vue-next' | 'react' | 'mobile-vue' | 'mobile-react'
16+
17+
/**
18+
* resolve `tdesign-icons'
19+
* @default false
20+
*/
21+
resolveIcons?: boolean
22+
}
23+
24+
function getSideEffects(importName: string, options: TDesignResolverOptions): SideEffectsInfo | undefined {
25+
const { library = 'vue', importStyle = 'css' } = options
26+
const fileName = kebabCase(importName)
27+
28+
if (!importStyle) return
29+
30+
if (importStyle === 'less') return `tdesign-${library}/esm/${fileName}/style`
31+
32+
return `tdesign-${library}/es/${fileName}/style`
33+
}
34+
35+
export function TDesignResolver(options: TDesignResolverOptions = {}): ComponentResolver {
36+
return {
37+
type: 'component',
38+
resolve: (name: string) => {
39+
const { library = 'vue' } = options
40+
41+
if (options.resolveIcons && name.match(/[a-z]Icon$/)) {
42+
return {
43+
importName: name,
44+
path: `tdesign-icons-${library}`,
45+
}
46+
}
47+
48+
if (name.match(/^T[A-Z]/)) {
49+
const importName = name.slice(1)
50+
51+
return {
52+
importName,
53+
path: `tdesign-${library}`,
54+
sideEffects: getSideEffects(importName, options),
55+
}
56+
}
57+
},
58+
}
59+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy