I have a Laravel 10 project using Vite. I succeed in compiling assets with this configuration :
vite.config.js
import laravel from 'laravel-vite-plugin'
import { defineConfig } from 'vite'
var config = {
plugins: [
laravel({
input: [
'resources/sass/app/appMaster.scss',
'resources/sass/admin/adminMaster.scss',
'resources/sass/errors/errorsMaster.scss',
'resources/js/app.js'],
refresh: true,
}),
],
build: {
assetsDir: '',
},
server: {
hmr: {
host: 'localhost',
},
}
}
export default defineConfig(({command, mode, ssrBuild}) => {
if (command === 'serve') {
config.publicDir = 'public';
config.build = {
assetsDir: '',
copyPublicDir: false,
emptyOutDir: true,
};
}
return config;
});
layout.blade.php
[...]
@vite(['resources/sass/app/appMaster.scss', 'resources/sass/admin/adminMaster.scss', 'resources/sass/errors/errorsMaster.scss', 'resources/js/app.js'])
[...]
As you can see my scss is split into three files. I have some routes groups and I don't want for example the adminMaster.scss to be used in app route group.
With laravel mix in an older project I'm using some middlewares to compiling assets according to the route group.
How can I do that with Vite?
I'm wondering if I have to make a different configuration because I understand that with
@vite(['resources/sass/app/appMaster.scss', 'resources/sass/admin/adminMaster.scss', 'resources/sass/errors/errorsMaster.scss', 'resources/js/app.js'])
all scss files are loading and can't be conditioned.
Is anyone already did it or have an idea?
Thanks