-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue.js
executable file
·55 lines (49 loc) · 1.61 KB
/
vue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import Vue from "vue/dist/vue.esm.js";
import App from './dist/app.vue';
import '@babel/polyfill';
// Fetch data from data attributes
const dataAttribute = document.querySelector('#route');
const componentRoute = dataAttribute.dataset.route;
const componentName = dataAttribute.dataset.name;
const identifier = '#' + componentName;
const dataID = dataAttribute.dataset.id;
const requireComponent = require.context(
// Look for files in the current directory
'./dist/vue/',
// Do not look in subdirectories
false,
// Include all .vue files
/[\w-]+\.vue$/
)
// For each matching file name...
requireComponent.keys().forEach((fileName) => {
// Get the component config
const componentConfig = requireComponent(fileName)
// Get the PascalCase version of the component name
const componentName = fileName
// Remove the "./_" from the beginning
.replace(/^\.\//, '')
// Remove the file extension from the end
.replace(/\.\w+$/, '')
// Split up kebabs
.split('-')
// Upper case
.map((kebab) => kebab.charAt(0).toUpperCase() + kebab.slice(1))
// Concatenated
.join('')
// Globally register the component
Vue.component(componentName, componentConfig.default || componentConfig)
})
// Create root element
new Vue({
components: { App },
data: function () {
return {
componentName: componentName,
componentRoute: componentRoute,
dataID: dataID
}
},
template: '<app></app>',
render: h => h(App)
}).$mount(identifier)