From 234380120e53996c9206b049cc1f042127a69b7c Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 20 May 2023 00:57:05 +0200 Subject: [PATCH] Load page components synchronously --- resources/js/app.js | 10 +++++----- resources/js/lib/requireModules.js | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/resources/js/app.js b/resources/js/app.js index aadfeced..252d14ba 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -24,14 +24,14 @@ Vue.use(PiniaVuePlugin); Vue.component('SvgSprite', () => import('./components/SvgSprite.js')); Vue.component('ILink', ILink); -// ---------------------------------- mixins ----------------------------------- -Vue.mixin(hasModule); -Vue.mixin(hasFlash); - // -------------------------------- Components --------------------------------- requireModules(require.context('./components/form', false, /\.vue$/, 'lazy'), Vue, 'f'); requireModules(require.context('./components/ui', false, /\.vue$/, 'lazy'), Vue, 'ui'); -requireModules(require.context('./components/page', false, /\.vue$/, 'lazy'), Vue, 'page'); +requireModules(require.context('./components/page', false, /\.vue$/), Vue, 'page'); + +// ---------------------------------- mixins ----------------------------------- +Vue.mixin(hasModule); +Vue.mixin(hasFlash); // ----------------------------------- init ------------------------------------ const el = document.getElementById('app'); diff --git a/resources/js/lib/requireModules.js b/resources/js/lib/requireModules.js index 85b1ceaf..7ef50c39 100644 --- a/resources/js/lib/requireModules.js +++ b/resources/js/lib/requireModules.js @@ -1,10 +1,11 @@ import {paramCase} from 'change-case'; export default function (context, Vue, prefix) { + var isAsync = context.name === 'webpackAsyncContext'; + context.keys().forEach((file) => { let componentName = paramCase(`${prefix}${file.replace(/^\.\/(.*?)\.vue$/g, '$1')}`); - console.log(componentName); - Vue.component(componentName, () => context(file)); + Vue.component(componentName, isAsync ? () => context(file) : context(file).default); }); }