thebigk's avatar
Level 13

Vite created assets on production server

I'm curious to know if I really need to run npm run build on the production server? Because this requires me to have npm installed on the production server.

If I remember correctly, this wasn't the case with assets produced by MIX. Can someone clarify?

0 likes
6 replies
Sinnbeck's avatar

I think it should be possible to build it locally and commit it to git. But be aware that your urls might be wrong. I haven't tested it myself as I build on production, but you might need to set this in your env before building (to the production url)

https://laravel.com/docs/9.x/vite#custom-base-urls

1 like
thebigk's avatar
Level 13

I see. What's the popular way to use Vite assets on production server? I guess everyone's installing npm on their production server?

Sinnbeck's avatar

@thebigk Personally I have installed it yes. I use zero downtime deployment to avoid downtime (ploi.io). I assume some people build it in their CI pipeline instead.

thebigk's avatar
Level 13

I use Forge. But I had to include npm run build in my deployment script. Was wondering if that's the right way to do it or I missed something in the documentation.

Sinnbeck's avatar

@thebigk I do the same with ploi. Just be sure that you either take the site down with a maintenance message or use zero downtime deployment. Vite deletes all the js/css files before generating new ones, so your site will be broken while it is building, unless you do one of those.

1 like
sudoanand's avatar

Its pretty easy to do, first change the output directory to some random location and once build is complete, move it to public/build.

I have written a tutorial here: https:// piehost.com/programming/deploy-laravel-vite-applications-with-zero-downtime

Please or to participate in this conversation.