如何为 Laravel Spark 自动注册 Vue 组件文件

How to auto register Vue component files for Laravel Spark

Laravel 的 app.js 文件包含一些注释掉的代码,用于在指定目录下添加所有 vue 组件:

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

此相同代码未包含在最新版本的 Laravel Spark 中,并且在复制过来时不起作用。如何在 Laravel Spark 的特定目录下自动注册任何 vue 组件文件?

在导入 Vue 之后和实例化应用的新 Vue 对象之前,将这段代码放在 app.js 文件中的某处:

const files = require.context('./', true, /\.vue$/i);
files.keys().map(key => Vue.component(files(key).name, files(key)));