To migrate from Laravel Mix to Vite, you can follow these steps:
- Install Vite and its plugins:
npm install vite @vitejs/plugin-vue laravel-vite-plugin --save-dev
- Create a
vite.config.jsfile in the root of your project:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [
laravel(),
vue(),
],
});
- Update your
webpack.mix.jsfile to remove all the bundling and compilation tasks, and only keep the asset copying tasks:
const mix = require('laravel-mix');
require('dotenv').config();
mix.copy('resources/css/app.css', 'public/css')
.copy('resources/js/app.js', 'public/js');
- Update your
app.blade.phpfile to use the new asset paths:
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
<script src="{{ mix('js/app.js') }}"></script>
- Test your application to make sure everything works as expected.
Note: If you have multiple entry points, you can use the vite-plugin-multi-entry plugin to handle them.