[Vuejs]-Laravel + Vue + Vite + defineAsyncComponent โ€“ Works with npm dev, fails with npm build

0๐Ÿ‘

I tried this way also but is not making use of defineAsyncComponent ๐Ÿ˜”

app.js file content:

import './bootstrap';
import { createApp } from 'vue';
import { defineAsyncComponent } from 'vue'

const app = createApp({});

let index = 0;
const components = []
Object.entries(import.meta.glob('./**/*.vue', { eager: true })).forEach(([path, definition]) => {
    
    index++
    var module_name = path.split('/').pop().replace(/\.\w+$/, '')
    const camelToDashed = module_name.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`).slice(1);
    components[index] = defineAsyncComponent( () => import('./components/'+camelToDashed+'.vue') )
    app.component(path.split('/').pop().replace(/\.\w+$/, ''), definition.default)

});

app.mount('#app');

Leave a comment