Skip to content

Commit 1841ca3

Browse files
authored
feat: modify vant resolver (#38)
1 parent 13fbe25 commit 1841ca3

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

examples/vue3/src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createApp } from 'vue'
22
import App from './App.vue'
33
import './index.css'
4-
import 'vant/lib/index.css'
54

65
createApp(App).mount('#app')

src/resolvers/vant.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
import { ComponentResolver } from '../types'
2+
import { kebabCase } from '../utils'
3+
4+
export interface VantResolverOptions {
5+
/**
6+
* import style along with components
7+
*
8+
* @default true
9+
*/
10+
importStyle?: boolean
11+
}
212

313
/**
414
* Resolver for Vant
515
*
616
* @link https://github.com/youzan/vant
717
*/
8-
export const VantResolver = (): ComponentResolver => (name: string) => {
9-
if (name.startsWith('Van'))
10-
return { importName: name.slice(3), path: 'vant' }
18+
export const VantResolver = (options: VantResolverOptions = {}): ComponentResolver => (name: string) => {
19+
const { importStyle = true } = options
20+
if (name.startsWith('Van')) {
21+
const partialName = name.slice(3)
22+
return {
23+
importName: partialName,
24+
path: 'vant/es',
25+
sideEffects: importStyle ? `vant/es/${kebabCase(partialName)}/style` : undefined,
26+
}
27+
}
1128
}

0 commit comments

Comments
 (0)