Skip to content

Commit

Permalink
feat(antdv): customize prefix whatever you want (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzheng14 authored and sxzz committed Aug 30, 2023
1 parent 534fbfa commit f88402a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/core/resolvers/antdv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ export interface AntDesignVueResolverOptions {
* @default 'ant-design-vue'
*/
packageName?: string
/**
* customize prefix of component
*/
prefix?: string
}

function getStyleDir(compName: string): string {
Expand Down Expand Up @@ -247,12 +251,13 @@ function getSideEffects(compName: string, options: AntDesignVueResolverOptions):
}
}
const primitiveNames = ['Affix', 'Anchor', 'AnchorLink', 'AutoComplete', 'AutoCompleteOptGroup', 'AutoCompleteOption', 'Alert', 'Avatar', 'AvatarGroup', 'BackTop', 'Badge', 'BadgeRibbon', 'Breadcrumb', 'BreadcrumbItem', 'BreadcrumbSeparator', 'Button', 'ButtonGroup', 'Calendar', 'Card', 'CardGrid', 'CardMeta', 'Collapse', 'CollapsePanel', 'Carousel', 'Cascader', 'Checkbox', 'CheckboxGroup', 'Col', 'Comment', 'ConfigProvider', 'DatePicker', 'MonthPicker', 'WeekPicker', 'RangePicker', 'QuarterPicker', 'Descriptions', 'DescriptionsItem', 'Divider', 'Dropdown', 'DropdownButton', 'Drawer', 'Empty', 'Form', 'FormItem', 'FormItemRest', 'Grid', 'Input', 'InputGroup', 'InputPassword', 'InputSearch', 'Textarea', 'Image', 'ImagePreviewGroup', 'InputNumber', 'Layout', 'LayoutHeader', 'LayoutSider', 'LayoutFooter', 'LayoutContent', 'List', 'ListItem', 'ListItemMeta', 'Menu', 'MenuDivider', 'MenuItem', 'MenuItemGroup', 'SubMenu', 'Mentions', 'MentionsOption', 'Modal', 'Statistic', 'StatisticCountdown', 'PageHeader', 'Pagination', 'Popconfirm', 'Popover', 'Progress', 'Radio', 'RadioButton', 'RadioGroup', 'Rate', 'Result', 'Row', 'Select', 'SelectOptGroup', 'SelectOption', 'Skeleton', 'SkeletonButton', 'SkeletonAvatar', 'SkeletonInput', 'SkeletonImage', 'Slider', 'Space', 'Spin', 'Steps', 'Step', 'Switch', 'Table', 'TableColumn', 'TableColumnGroup', 'TableSummary', 'TableSummaryRow', 'TableSummaryCell', 'Transfer', 'Tree', 'TreeNode', 'DirectoryTree', 'TreeSelect', 'TreeSelectNode', 'Tabs', 'TabPane', 'Tag', 'CheckableTag', 'TimePicker', 'TimeRangePicker', 'Timeline', 'TimelineItem', 'Tooltip', 'Typography', 'TypographyLink', 'TypographyParagraph', 'TypographyText', 'TypographyTitle', 'Upload', 'UploadDragger', 'LocaleProvider', 'FloatButton', 'FloatButtonGroup', 'Qrcode', 'Watermark', 'Segmented', 'Tour']
const prefix = 'A'

let antdvNames: Set<string>

function genAntdNames(primitiveNames: string[]): void {
antdvNames = new Set(primitiveNames.map(name => `${prefix}${name}`))
// use primitiveNames to construct antdvNames,
// in order to make options.resolvePrefix compatible
antdvNames = new Set(primitiveNames)
}
genAntdNames(primitiveNames)

Expand Down Expand Up @@ -282,22 +287,25 @@ export function AntDesignVueResolver(options: AntDesignVueResolverOptions = {
return {
type: 'component',
resolve: (name: string) => {
// if options.prefix is undefined, then give it a default value 'A'
options.prefix === undefined && (options.prefix = 'A')
if (options.resolveIcons && name.match(/(Outlined|Filled|TwoTone)$/)) {
return {
name,
from: '@ant-design/icons-vue',
}
}

if (isAntdv(name) && !options?.exclude?.includes(name)) {
const importName = name.slice(1)
let prefix
// divide component name and prefix
[name, prefix] = [name.slice(options.prefix.length), name.slice(0, options.prefix.length)]
if (prefix === options.prefix && isAntdv(name) && !options?.exclude?.includes(name)) {
// console.log('importName----', importName)
const { cjs = false, packageName = 'ant-design-vue' } = options
const path = `${packageName}/${cjs ? 'lib' : 'es'}`
return {
name: getImportName(importName),
from: path,
sideEffects: getSideEffects(importName, options),
sideEffects: getSideEffects(name, options),
}
}
},
Expand Down

0 comments on commit f88402a

Please sign in to comment.