So before, with laravel MIX, in the webpack.mix.js
file, you can write
mix.js('resources/js/app.js', 'public/js')
.js('resources/js/header.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.sass('resources/sass/main.scss', 'public/css')
.sass('resources/sass/header.scss', 'public/css')
and it will be compiled to public/asset
separately. Like the JS files will be compiled to public/asset/js
and the sass files will be at public/asset/css
. And when you put the files in the head
of the blaze.php
in your views you simply write
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
<link rel="stylesheet" href="{{ asset('css/main.css') }}">
<link rel="stylesheet" href="{{ asset('css/header.css') }}">
<script type="text/javascript" src="{{ asset('js/app.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/header.js') }}"></script>
How do I incorporate this with the now Laravel-Vite? Because when I run npm run dev
the seperate files scss
and js
just gets compiled together in a single folder which is public/build/assets/
. They are not being separated as to whether js file goes to js folder and scss file goes to css folder.
Here is what it looks like in my vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/sass/app.scss',
'resources/sass/main.scss',
'resources/js/app.js',
],
refresh: true,
}),
],
});