File tree Expand file tree Collapse file tree 1 file changed +26
-4
lines changed
Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Original file line number Diff line number Diff line change 11import Vue from 'vue'
2- import HelloWorld from './components/HelloWorld.vue'
3- // Import all components here
42
5- Vue . component ( 'HelloWorld' , HelloWorld )
6- // Attach all components to Vue here
3+ // Automatically register all Vue components located within the /src/components folder.
4+
5+ const requireComponent = require . context (
6+ // The relative path of the components folder
7+ './components' ,
8+ // Whether or not to look in subfolders
9+ true ,
10+ // The regular expression used to match base component filenames
11+ / [ A - Z ] \w + \. ( v u e | j s ) $ /
12+ )
13+
14+ requireComponent . keys ( ) . forEach ( fileName => {
15+ // Get component config
16+ const componentConfig = requireComponent ( fileName )
17+
18+ const cleanFileName = fileName . replace ( / ^ \. \/ ( .* ) \. \w + $ / , '$1' )
19+
20+ // Register component globally
21+ Vue . component (
22+ cleanFileName ,
23+ // Look for the component options on `.default`, which will
24+ // exist if the component was exported with `export default`,
25+ // otherwise fall back to module's root.
26+ componentConfig . default || componentConfig
27+ )
28+ } )
You can’t perform that action at this time.
0 commit comments