Skip to content

Commit

Permalink
feat(bootstrap-vue): add support for aliases and directives (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrunel authored Jul 25, 2022
1 parent f43f073 commit b5f293f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,22 @@ Supported Resolvers:

- [Ant Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/antdv.ts)
- [Arco Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/arco.ts)
- [BootstrapVue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/bootstrap-vue.ts)
- [Element Plus](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-plus.ts)
- [Element UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-ui.ts)
- [Headless UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/headless-ui.ts)
- [IDux](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/idux.ts)
- [Inkline](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/inkline.ts)
- [Naive UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/naive-ui.ts)
- [Prime Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/prime-vue.ts)
- [Quasar](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/quasar.ts)
- [TDesign](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts)
- [Vant](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vant.ts)
- [VEUI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/veui.ts)
- [Varlet UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/varlet-ui.ts)
- [VEUI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/veui.ts)
- [View UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/view-ui.ts)
- [Vuetify](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vuetify.ts)
- [VueUse Components](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse.ts)
- [Quasar](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/quasar.ts)
- [TDesign](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts)

```ts
// vite.config.js
Expand Down
80 changes: 75 additions & 5 deletions src/core/resolvers/bootstrap-vue.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,86 @@
import type { ComponentResolver } from '../../types'

export interface BootstrapVueResolverOptions {
/**
* Auto import for directives.
*
* @default true
*/
directives?: boolean
}

const COMPONENT_ALIASES: Record<string, string> = {
BBtn: 'BButton',
BBtnClose: 'BButtonClose',
BBtnGroup: 'BButtonGroup',
BBtnToolbar: 'BButtonToolbar',
BCheck: 'BFormCheckbox',
BCheckbox: 'BFormCheckbox',
BCheckboxGroup: 'BFormCheckboxGroup',
BCheckGroup: 'BFormCheckboxGroup',
BDatalist: 'BFormDatalist',
BDd: 'BDropdown',
BDdDivider: 'BDropdownDivider',
BDdForm: 'BDropdownForm',
BDdGroup: 'BDropdownGroup',
BDdHeader: 'BDropdownHeader',
BDdItem: 'BDropdownItem',
BDdItemButton: 'BDropdownItemButton',
BDdItemBtn: 'BDropdownItemButton',
BDdText: 'BDropdownText',
BDropdownItemBtn: 'BDropdownItemButton',
BFile: 'BFormFile',
BFormDatepicker: 'BDatepicker',
BInput: 'BFormInput',
BNavDd: 'BNavItemDropdown',
BNavDropdown: 'BNavItemDropdown',
BNavItemDd: 'BNavItemDropdown',
BNavToggle: 'BNavbarToggle',
BRadio: 'BFormRadio',
BRadioGroup: 'BFormRadioGroup',
BRating: 'BFormRating',
BSelect: 'BFormSelect',
BSelectOption: 'BFormSelectOption',
BSelectOptionGroup: 'BFormSelectOptionGroup',
BSpinbutton: 'BFormSpinbutton',
BTag: 'BFormTag',
BTags: 'BFormTags',
BTextarea: 'BFormTextarea',
BTimepicker: 'BFormTimepicker',
}

/**
* Resolver for BootstrapVue
*
* @link https://github.com/bootstrap-vue/bootstrap-vue
*/
export function BootstrapVueResolver(): ComponentResolver {
return {
export function BootstrapVueResolver(_options: BootstrapVueResolverOptions = {}): ComponentResolver[] {
const options = { directives: true, ..._options }
const resolvers: ComponentResolver[] = [{
type: 'component',
resolve: (name: string) => {
if (name.match(/^B[A-Z]/))
return { name, from: 'bootstrap-vue' }
resolve: (name) => {
if (name.match(/^B[A-Z]/)) {
return {
name: COMPONENT_ALIASES[name] || name,
from: 'bootstrap-vue',
}
}
},
}]

if (options.directives) {
resolvers.push({
type: 'directive',
resolve: (name) => {
if (name.match(/^B[A-Z]/)) {
return {
name: `V${name}`,
from: 'bootstrap-vue',
}
}
},
})
}

return resolvers
}

0 comments on commit b5f293f

Please sign in to comment.