Created
March 6, 2018 01:49
-
-
Save rayfranco/99a7c7acdeec860e99b87d6cb1201afb to your computer and use it in GitHub Desktop.
Autoload Vue components folder
This file contains hidden or 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
// /components/subfolder/index.js | |
const context = require.context('./', false, /\.vue/) | |
export default context.keys().reduce((obj, key) => { | |
let name = key.match(/(\w+)\.vue$/)[1] | |
obj[name] = context(key).default | |
return obj | |
}, {}) |
This file contains hidden or 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 SubfolderComponents from './subfolder' | |
export default { | |
components: { | |
// This will add all components in subfolder | |
...SubfolderComponents | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment