1+ import Debug from 'debug'
12import type { ComponentInfo , ComponentResolver } from '../../types'
2- import { kebabCase } from '../utils'
3+ import { kebabCase , pascalCase } from '../utils'
4+ const debug = Debug ( 'unplugin-vue-components:resolvers:arco' )
35
46const matchComponents = [
57 {
@@ -139,6 +141,31 @@ function getComponentStyleDir(importName: string, importStyle: boolean | 'css' |
139141 return `@arco-design/web-vue/es/${ componentDir } /style/css.js`
140142}
141143
144+ function canResolveIcons ( options ?: ResolveIconsOption ) : options is AllowResolveIconOption {
145+ if ( options === undefined )
146+ return false
147+ if ( typeof options === 'boolean' )
148+ return options
149+ else
150+ return options . enable
151+ }
152+
153+ function getResolveIconPrefix ( options ?: ResolveIconsOption ) {
154+ if ( canResolveIcons ( options ) ) {
155+ if ( typeof options === 'boolean' && options )
156+ return ''
157+ else if ( options . enable )
158+ return options . iconPrefix ?? ''
159+ else
160+ return ''
161+ }
162+ return ''
163+ }
164+
165+ export type DisallowResolveIconOption = undefined | false | { enable : false }
166+ export type AllowResolveIconOption = true | { enable : true ; iconPrefix ?: string }
167+ export type ResolveIconsOption = DisallowResolveIconOption | AllowResolveIconOption
168+
142169export interface ArcoResolverOptions {
143170 /**
144171 * import style css or less with components
@@ -151,7 +178,7 @@ export interface ArcoResolverOptions {
151178 *
152179 * @default false
153180 */
154- resolveIcons ?: boolean
181+ resolveIcons ?: ResolveIconsOption
155182 /**
156183 * Control style automatic import
157184 *
@@ -175,10 +202,18 @@ export function ArcoResolver(
175202 return {
176203 type : 'component' ,
177204 resolve : ( name : string ) => {
178- if ( options . resolveIcons && name . match ( / ^ I c o n / ) ) {
179- return {
180- name,
181- from : '@arco-design/web-vue/es/icon' ,
205+ if ( canResolveIcons ( options . resolveIcons ) ) {
206+ const iconPrefix = pascalCase ( getResolveIconPrefix ( options . resolveIcons ) )
207+ const newNameRegexp = new RegExp ( `^${ iconPrefix } Icon` )
208+ if ( newNameRegexp . test ( name ) ) {
209+ debug ( 'found icon component name %s' , name )
210+ const rawComponentName = name . slice ( iconPrefix . length )
211+ debug ( 'found icon component raw name %s' , rawComponentName )
212+ return {
213+ name : rawComponentName ,
214+ as : name ,
215+ from : '@arco-design/web-vue/es/icon' ,
216+ }
182217 }
183218 }
184219 if ( name . match ( / ^ A [ A - Z ] / ) ) {
0 commit comments