Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aa913f6

Browse files
Implement require.context to load base components
1 parent 850d306 commit aa913f6

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

‎src/components/_globals.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Vue from 'vue'
2+
import upperFirst from 'lodash/upperFirst'
3+
import camelCase from 'lodash/camelCase'
4+
5+
const requireComponent = require.context(
6+
// The relative path of the components folder
7+
'.',
8+
// Whether or not to look in subfolders
9+
false,
10+
// The regular expression used to match base component filenames
11+
/Base[A-Z]\w+\.(vue|js)$/
12+
)
13+
14+
requireComponent.keys().forEach(fileName => {
15+
// Get component config
16+
const componentConfig = requireComponent(fileName)
17+
18+
// Get PascalCase name of component
19+
const componentName = upperFirst(
20+
camelCase(
21+
// Gets the file name regardless of folder depth
22+
fileName
23+
.split('/')
24+
.pop()
25+
.replace(/\.\w+$/, '')
26+
)
27+
)
28+
29+
30+
// Register component globally
31+
Vue.component(
32+
componentName,
33+
// Look for the component options on `.default`, which will
34+
// exist if the component was exported with `export default`,
35+
// otherwise fall back to module's root.
36+
componentConfig.default || componentConfig
37+
)
38+
})

‎src/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'
55
import 'bootstrap/dist/css/bootstrap.css'
66
import 'bootstrap-vue/dist/bootstrap-vue.css'
77

8+
// Globally register all `_base`-prefixed components
9+
import './components/_globals'
10+
811
// Install BootstrapVue
912
Vue.use(BootstrapVue)
1013
// Optionally install the BootstrapVue icon components plugin

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /