Migration to Official Laravel Vite Plugin
April 28, 2023 ยท View on GitHub
This guide is a rough migration guide to move from Innocenzi's vite integration to the new Laravel one. If you notice any issues or omissions, feel free to pr :)
LP = Legacy Plugin, aka innocenzi/laravel-vite
-
Remove
innocenzi/laravel-vitefrom yourcomposer.jsonand runcomposer update -
Run
yarn remove laravel-viteand thenyarn add laravel-vite-pluginto swap to the official plugin -
Under the plugins section in your
vite.config.ts, create a new laravel plugin instance and port your LP settings over.- Swap the old import to the new one
import laravel from 'laravel-vite-plugin' - Head over to your LP
vite.phpconfig file, and migrate the entry points over to theinputkey in the new config. Note that the laravel plugin wants specific files, and not just a directory like the LP. - If you are using valet with the LP, swap from the old config option to the
valetTlskey, specifying your domain. - Migrate your aliases from
vite.phpto theresolve->aliasoption in the vite config, in particular the@alias.
Example config after migration
defineConfig({ optimizeDeps: { include: [ 'ziggy', // Include ziggy in build ], }, resolve: { alias: { 'ziggy': 'vendor/tightenco/ziggy/dist/vue.m.js', // ziggy alias '@': 'resources', // ported alias from vite.php } }, plugins: [ vue(), // Other plugins laravel({ input: [ // Entrypoints 'resources/js/main.ts', 'resources/js/ziggy.js', ], valetTls: 'domain.test', // Valet domain }) ] }) - Swap the old import to the new one
-
Update the
@viteimport in your base blade template to contain the specific entrypoints, instead of the generic entry before, ie:-@vite +@vite('resources/js/main.ts')