|
| 1 | +// Core imports |
| 2 | +import Vue from 'vue'; |
| 3 | +import upperFirst from 'lodash/upperFirst'; |
| 4 | +import camelCase from 'lodash/camelCase'; |
| 5 | +import router from './router/index'; |
| 6 | +import store from './store'; |
| 7 | +import App from './components/App'; |
| 8 | +import { FontAwesomeIcon } from './icons'; |
| 9 | + |
| 10 | +// 3th imports |
| 11 | +import { sync } from 'vuex-router-sync'; |
| 12 | +import axios from 'axios'; |
| 13 | +import ElementUI from 'element-ui'; |
| 14 | +import locale from 'element-ui/lib/locale/lang/en' |
| 15 | + |
| 16 | +// CSS imports |
| 17 | +import './styles/main.sass' |
| 18 | + |
| 19 | +// Configurations |
| 20 | +Vue.use(ElementUI, { locale }); |
| 21 | +Vue.component('icon', FontAwesomeIcon); |
| 22 | +Vue.prototype.$http = axios; |
| 23 | +sync(store, router); |
| 24 | + |
| 25 | +// Mode details on: https://vuejs.org/v2/guide/components-registration.html |
| 26 | +const requireComponent = require.context( |
| 27 | + // The relative path of the components folder |
| 28 | + './components', |
| 29 | + // Whether or not to look in subfolders |
| 30 | + true, |
| 31 | + // The regular expression used to match base component filenames |
| 32 | + /base[A-Z]\w+\.(vue|js)$/ |
| 33 | +); |
| 34 | + |
| 35 | +requireComponent.keys().forEach(fileName => { |
| 36 | + // Get component config |
| 37 | + const componentConfig = requireComponent(fileName); |
| 38 | + |
| 39 | + // Get PascalCase name of component |
| 40 | + const componentName = upperFirst( |
| 41 | + camelCase( |
| 42 | + // Strip the leading `./` and extension from the filename |
| 43 | + fileName.replace(/base/, '').replace(/^\.\/(.*)\.\w+$/, '$1') |
| 44 | + ) |
| 45 | + ); |
| 46 | + |
| 47 | + // Register component globally |
| 48 | + Vue.component( |
| 49 | + componentName, |
| 50 | + // Look for the component options on `.default`, which will |
| 51 | + // exist if the component was exported with `export default`, |
| 52 | + // otherwise fall back to module's root. |
| 53 | + componentConfig.default || componentConfig |
| 54 | + ); |
| 55 | +}); |
| 56 | + |
| 57 | +new Vue({ // eslint-disable-line |
| 58 | + el: '#app', |
| 59 | + store, |
| 60 | + router, |
| 61 | + ...App |
| 62 | +}); |
0 commit comments