File tree Expand file tree Collapse file tree 6 files changed +60
-6
lines changed Expand file tree Collapse file tree 6 files changed +60
-6
lines changed Original file line number Diff line number Diff line change 1
1
import path from 'path'
2
2
import { UserConfig } from 'vite'
3
3
import Vue from '@vitejs/plugin-vue'
4
- import ViteComponents from 'vite-plugin-components'
4
+ import ViteComponents , { VantResolver } from 'vite-plugin-components'
5
5
import Markdown from 'vite-plugin-md'
6
6
// @ts -expect-error
7
7
import SVG from 'vite-plugin-vue-svg'
@@ -27,11 +27,7 @@ const config: UserConfig = {
27
27
if ( name === 'MyCustom' )
28
28
return '/src/CustomResolved.vue'
29
29
} ,
30
- // auto import from ui library Vant
31
- ( name : string ) => {
32
- if ( name . startsWith ( 'Van' ) )
33
- return { importName : name . slice ( 3 ) , path : 'vant' }
34
- } ,
30
+ VantResolver ( ) ,
35
31
] ,
36
32
} ) ,
37
33
] ,
Original file line number Diff line number Diff line change @@ -38,5 +38,6 @@ function VitePluginComponents(options: Options = {}): Plugin {
38
38
39
39
export * from './helpers/libraryResolver'
40
40
export * from './types'
41
+ export * from './resolvers'
41
42
export { camelCase , pascalCase , kebabCase } from './utils'
42
43
export default VitePluginComponents
Original file line number Diff line number Diff line change
1
+ import { ComponentResolver } from '../types'
2
+
3
+ /**
4
+ * Resolver for Ant Design Vue
5
+ *
6
+ * See https://github.com/antfu/vite-plugin-components/issues/26#issuecomment-789767941 for more details
7
+ *
8
+ * @author @yangss 3
9
+ * @link https://antdv.com/
10
+ */
11
+ export const AntDesignVueResolver = ( ) : ComponentResolver => ( name : string ) => {
12
+ if ( name . match ( / ^ A [ A - Z ] / ) )
13
+ return { importName : name . slice ( 1 ) , path : 'ant-design-vue/es' }
14
+ }
Original file line number Diff line number Diff line change
1
+ import { ComponentResolver } from '../types'
2
+
3
+ export interface ElementPlusResolverOptions {
4
+ /**
5
+ * import style along with components
6
+ *
7
+ * @default true
8
+ */
9
+ importStyle ?: boolean
10
+ }
11
+
12
+ /**
13
+ * Resolver for Element Plus
14
+ *
15
+ * See https://github.com/antfu/vite-plugin-components/pull/28 for more details
16
+ *
17
+ * @author @develar
18
+ * @link https://element-plus.org/#/en-US
19
+ */
20
+ export const ElementPlusResolver = ( options : ElementPlusResolverOptions = { } ) : ComponentResolver => ( name : string ) => {
21
+ const { importStyle = true } = options
22
+ if ( name . startsWith ( 'El' ) ) {
23
+ const partialName = name [ 2 ] . toLowerCase ( ) + name . substring ( 3 ) . replace ( / [ A - Z ] / g, l => `-${ l . toLowerCase ( ) } ` )
24
+ return {
25
+ path : `element-plus/es/el-${ partialName } ` ,
26
+ sideEffects : importStyle ? `element-plus/packages/theme-chalk/src/${ partialName } .scss` : undefined ,
27
+ }
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ export * from './antdv'
2
+ export * from './element-plus'
3
+ export * from './vant'
Original file line number Diff line number Diff line change
1
+ import { ComponentResolver } from '../types'
2
+
3
+ /**
4
+ * Resolver for Vant
5
+ *
6
+ * @link https://github.com/youzan/vant
7
+ */
8
+ export const VantResolver = ( ) : ComponentResolver => ( name : string ) => {
9
+ if ( name . startsWith ( 'Van' ) )
10
+ return { importName : name . slice ( 3 ) , path : 'vant' }
11
+ }
You can’t perform that action at this time.
0 commit comments