I have this Laravel 10 and Vue 2.7 project and I converted it from Mix to Laravel Vite. Here is my current folder structures:
/resources
----/js
--------/container
------------/student
----------------app.js
----------------cancel.js
------------/teacher
----------------app.js
----------------apply.js
--------/components
------------/student
----------------app.vue
----------------cancel.vue
------------/teacher
----------------app.vue
----------------apply.vue
----/view
--------/student
------------app.blade.php
------------cancel.blade.php
--------/teacher
------------app.blade.php
------------apply.blade.php
How do I write my vite.config.js? I have tried this
export default defineConfig({
plugins: [
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false
}
}
}),
laravel({
input: [
...glob.sync('resources/js/container/**/*.js')
],
refresh: true
}),
],
resolve: {
alias: {
vue: 'vue/dist/vue.esm.js',
}
}
})
But the generated files after npm run build are located in just one folder public/build/assets/.
Your Laravel Vite project's folder structure appears to be set up differently than the Laravel Vite installation by default. To organise your assets and views, Laravel Vite use a particular folder structure by default. The vite.config.js file can be changed to alter the output folder structure, though.
You want to output your assets in your situation to a separate location. By including the build option in your vite.config.js file, you can do this. Here is how to edit your vite.config.js file:
To reflect your actual folder structure, make sure to adjust the locations in the laravel.input and laravel.views arrays.
After making these modifications, npm run build will output your assets to the public/build folder according to the outDir option you chose.