Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Akryum
Created March 11, 2018 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akryum/049094d3625bed68e5574abe195f246e to your computer and use it in GitHub Desktop.
Save Akryum/049094d3625bed68e5574abe195f246e to your computer and use it in GitHub Desktop.
Register all base components
// --- Base components ---
import Vue from 'vue'
// To extract the component name
const nameReg = /([a-z0-9]+)\./i
function registerGlobalComponents (components) {
components.keys().forEach(key => {
const name = key.match(nameReg)[1]
Vue.component(name, {
name,
...components(key).default,
})
})
}
// Require all the components that start with 'BaseXXX.vue'
let components = require.context('@/common', true, /Base[a-z0-9]+\.(jsx?|vue)$/i)
registerGlobalComponents(components)
// Webpack HMR
if (module.hot) {
module.hot.accept(components.id, () => {
const components = require.context('@/common', true, /Base[a-z0-9]+\.(jsx?|vue)$/i)
registerGlobalComponents(components)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment