sunscreem's avatar

Auto-loading vue components?

Hey Folks,

We used to have this in laravel (5.6 ish onwards):

const files = require.context('./', true, /\.vue$/i)
files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))

In a clean laravel install it used to be in the bootstrap.js file and, as you can see, it auto-loaded all vue components.

There's no sign of this anymore. I'm guessing "best practice" is to load the components as we need them?

If so is that a significant improvement? Seems a bit more faff.

0 likes
1 reply
fylzero's avatar
fylzero
Best Answer
Level 67

@sunscreem This is added with the laravel/ui package in later versions.

https://github.com/laravel/ui

If you install laravel/ui with the Vue php artisan ui vue or Vue auth php artisan ui vue --auth commands you will see this return.

1 like

Please or to participate in this conversation.