Laravel Vite

How to use Laravel vite in your package

Max Hutschenreiter -

Developing Laravle Packages is always a bit more difficult than a base application. Special in packages with assets, it's becoming very thin on content. Today I ran into a problem with using Laravel Vite in a package and the main application.

Assuming you have a Laravel app shipping with Vite. After compiling your assets, you will get a folder /public/build/. In this folder, you have the manifest.json and a /assets folder. The manifest.json specify all the paths and tells your @vite directive in your blade file there to look for the files.
In your Package, you have the same structure. If you now just publish the assets with your Package Service Provider, it will overwrite your existing manifest.json. This would result in the problem that Vite can no longer find your asset files.

To solve this problem, you need to configure a different building path in Vite. 
In your vite.config.js you need to define your build directory. In this example, I used vendor/modular/admin_panel. You can use vendor/package_name. That would do the trick.
vide.config.js laravel config


In your blade file, you need to load Vite with the same paths.
blade vite code


In your ServiceProvider you need to specify the asset's publish paths.
Package Service Provider


Now your package assets are independent of the assets in your Laravel Application.  You need to build the assets in your Laravel Application and your Package. At the end, publish your assets with your Service Provider.
Publish assets command

I hope this helps you save some time. If you found a better way write me a comment :) 
Tags: Laravel · package · Laravel Vite

Want products news and updates?

Sign up for our newsletter to stay up to date.

We care about the protection of your data. Read our Privacy Policy.

Impressions from our Team

  • Happy birthday 🎁🎈🎂 Filip - #

  • Another day another #mandarinacakeshop 🎂 😀 - #

  • Happy Birthday Ognjen! And marry Christmas to all other 🎄#notacakeshop - #

  • #Office #Garden - #

  • #workhard - #

  • #belgrade #skyline - #

  • #happybirthday Phil :) - #

  • #happybirthday Stefan 🥂 - #

  • #happybirthday Lidija 🍾 - #

  • Say hi 👋 to our newest team member ☕️ - #

  • #bithday #cake 😻 - #

  • #stayathome #homeoffice #42coders - #

  • #stayathome #homeoffice #42coders #starwars :) - #

  • #stayathome #homeoffice #42coders - #

  • We had a really nice time with #laracononline #laravel - #

  • Happy Birthday 🎂 Miloš - #

  • Happy Birthday 🎂Nikola - #

  • #42coders #christmas #dinner what a nice evening :) - #

  • Happy Birthday 🎂 Ognjen - #

  • Wish you all a merry Christmas 🎄🎁 - #

See more!

© 2024 42coders All rights reserved.