Skip to content

Instantly share code, notes, and snippets.

@rayfranco
Created March 6, 2018 01:49
Show Gist options
  • Save rayfranco/99a7c7acdeec860e99b87d6cb1201afb to your computer and use it in GitHub Desktop.
Save rayfranco/99a7c7acdeec860e99b87d6cb1201afb to your computer and use it in GitHub Desktop.
Autoload Vue components folder
// /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
}, {})
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