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 11import path from 'path'
22import { UserConfig } from 'vite'
33import Vue from '@vitejs/plugin-vue'
4- import ViteComponents from 'vite-plugin-components'
4+ import ViteComponents , { VantResolver } from 'vite-plugin-components'
55import Markdown from 'vite-plugin-md'
66// @ts -expect-error
77import SVG from 'vite-plugin-vue-svg'
@@ -27,11 +27,7 @@ const config: UserConfig = {
2727 if ( name === 'MyCustom' )
2828 return '/src/CustomResolved.vue'
2929 } ,
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 ( ) ,
3531 ] ,
3632 } ) ,
3733 ] ,
Original file line number Diff line number Diff line change @@ -38,5 +38,6 @@ function VitePluginComponents(options: Options = {}): Plugin {
3838
3939export * from './helpers/libraryResolver'
4040export * from './types'
41+ export * from './resolvers'
4142export { camelCase , pascalCase , kebabCase } from './utils'
4243export 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