Laravel(5.8) and VUE work very nice togheter, but my app.js is getting to big.
For example, i have the following app.js:
window.Vue = require('vue');
window.Vue.component('Comp1', require('./components/Comp1.vue').default);
window.Vue.component('Comp2', require('./components/Comp2.vue').default);
window.Vue.component('Comp3', require('./components/Comp3.vue').default);
window.mainApp = new Vue({
el: '#app'
});
In the real case, I have around 30 components + third party, witch results in a 1.2mb JS for production.
So, I'm tring to break the app.js file in many 'area related' js, just split, so I wuld have someting like:
app.js:
window.Vue = require('vue');
window.mainApp = new Vue({
el: '#app'
});
appMainComp.js:
window.Vue.component('Comp1', require('./components/Comp1.vue').default);
window.Vue.component('Comp2', require('./components/Comp2.vue').default);
appOtherComp.js:
window.Vue.component('Comp3', require('./components/Comp3.vue').default);
Now, the catch. Everthing that I register after the app.js "window.mainApp = new Vue({ el: '#app'});" do not register.
So, is there a way to register a component after my 'mainApp' is created? Something like
mainApp.addComponent('./components/Comp1.vue');
Or any other way to break the app.js in mutiple files?