Created
March 11, 2018 17:26
-
-
Save Akryum/049094d3625bed68e5574abe195f246e to your computer and use it in GitHub Desktop.
Register all base components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- 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