Created
June 14, 2022 07:19
-
-
Save KarmaBlackshaw/58da959bbc6aa0e86a5c2473cec31e61 to your computer and use it in GitHub Desktop.
Vue2 Register Base Components Plugin
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
import upperFirst from 'lodash/upperFirst' | |
import camelCase from 'lodash/camelCase' | |
export default { | |
install: (Vue, options) => { | |
const requireComponent = require.context('../components', false, (/Base[A-Z]\w+\.(vue|js)$/)) | |
requireComponent.keys().forEach(fileName => { | |
// Get component config | |
const componentConfig = requireComponent(fileName) | |
// Get PascalCase name of component | |
const componentName = upperFirst(camelCase(fileName.split('/').pop().replace(/\.\w+$/, ''))) | |
Vue.component(componentName, componentConfig.default || componentConfig) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment