Skip to content

Commit b5f293f

Browse files
authored
feat(bootstrap-vue): add support for aliases and directives (#470)
1 parent f43f073 commit b5f293f

File tree

2 files changed

+79
-8
lines changed

2 files changed

+79
-8
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,22 @@ Supported Resolvers:
186186

187187
- [Ant Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/antdv.ts)
188188
- [Arco Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/arco.ts)
189+
- [BootstrapVue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/bootstrap-vue.ts)
189190
- [Element Plus](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-plus.ts)
190191
- [Element UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-ui.ts)
191192
- [Headless UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/headless-ui.ts)
192193
- [IDux](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/idux.ts)
193194
- [Inkline](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/inkline.ts)
194195
- [Naive UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/naive-ui.ts)
195196
- [Prime Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/prime-vue.ts)
197+
- [Quasar](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/quasar.ts)
198+
- [TDesign](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts)
196199
- [Vant](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vant.ts)
197-
- [VEUI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/veui.ts)
198200
- [Varlet UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/varlet-ui.ts)
201+
- [VEUI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/veui.ts)
199202
- [View UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/view-ui.ts)
200203
- [Vuetify](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vuetify.ts)
201204
- [VueUse Components](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse.ts)
202-
- [Quasar](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/quasar.ts)
203-
- [TDesign](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/tdesign.ts)
204205

205206
```ts
206207
// vite.config.js

src/core/resolvers/bootstrap-vue.ts

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,86 @@
11
import type { ComponentResolver } from '../../types'
22

3+
export interface BootstrapVueResolverOptions {
4+
/**
5+
* Auto import for directives.
6+
*
7+
* @default true
8+
*/
9+
directives?: boolean
10+
}
11+
12+
const COMPONENT_ALIASES: Record<string, string> = {
13+
BBtn: 'BButton',
14+
BBtnClose: 'BButtonClose',
15+
BBtnGroup: 'BButtonGroup',
16+
BBtnToolbar: 'BButtonToolbar',
17+
BCheck: 'BFormCheckbox',
18+
BCheckbox: 'BFormCheckbox',
19+
BCheckboxGroup: 'BFormCheckboxGroup',
20+
BCheckGroup: 'BFormCheckboxGroup',
21+
BDatalist: 'BFormDatalist',
22+
BDd: 'BDropdown',
23+
BDdDivider: 'BDropdownDivider',
24+
BDdForm: 'BDropdownForm',
25+
BDdGroup: 'BDropdownGroup',
26+
BDdHeader: 'BDropdownHeader',
27+
BDdItem: 'BDropdownItem',
28+
BDdItemButton: 'BDropdownItemButton',
29+
BDdItemBtn: 'BDropdownItemButton',
30+
BDdText: 'BDropdownText',
31+
BDropdownItemBtn: 'BDropdownItemButton',
32+
BFile: 'BFormFile',
33+
BFormDatepicker: 'BDatepicker',
34+
BInput: 'BFormInput',
35+
BNavDd: 'BNavItemDropdown',
36+
BNavDropdown: 'BNavItemDropdown',
37+
BNavItemDd: 'BNavItemDropdown',
38+
BNavToggle: 'BNavbarToggle',
39+
BRadio: 'BFormRadio',
40+
BRadioGroup: 'BFormRadioGroup',
41+
BRating: 'BFormRating',
42+
BSelect: 'BFormSelect',
43+
BSelectOption: 'BFormSelectOption',
44+
BSelectOptionGroup: 'BFormSelectOptionGroup',
45+
BSpinbutton: 'BFormSpinbutton',
46+
BTag: 'BFormTag',
47+
BTags: 'BFormTags',
48+
BTextarea: 'BFormTextarea',
49+
BTimepicker: 'BFormTimepicker',
50+
}
51+
352
/**
453
* Resolver for BootstrapVue
554
*
655
* @link https://github.com/bootstrap-vue/bootstrap-vue
756
*/
8-
export function BootstrapVueResolver(): ComponentResolver {
9-
return {
57+
export function BootstrapVueResolver(_options: BootstrapVueResolverOptions = {}): ComponentResolver[] {
58+
const options = { directives: true, ..._options }
59+
const resolvers: ComponentResolver[] = [{
1060
type: 'component',
11-
resolve: (name: string) => {
12-
if (name.match(/^B[A-Z]/))
13-
return { name, from: 'bootstrap-vue' }
61+
resolve: (name) => {
62+
if (name.match(/^B[A-Z]/)) {
63+
return {
64+
name: COMPONENT_ALIASES[name] || name,
65+
from: 'bootstrap-vue',
66+
}
67+
}
1468
},
69+
}]
70+
71+
if (options.directives) {
72+
resolvers.push({
73+
type: 'directive',
74+
resolve: (name) => {
75+
if (name.match(/^B[A-Z]/)) {
76+
return {
77+
name: `V${name}`,
78+
from: 'bootstrap-vue',
79+
}
80+
}
81+
},
82+
})
1583
}
84+
85+
return resolvers
1686
}

0 commit comments

Comments
 (0)