laravel / vite-plugin

Laravel plugin for Vite.
MIT License
804 stars 152 forks source link

Zero downtime #292

Closed MohammadZarifiyan closed 7 months ago

MohammadZarifiyan commented 7 months ago

Hello. When I run the npm run build command, the server gives the users an 500 error and the Vite Manifest Not Found error is recorded in laravel.log. Please add a feature not to delete the previous manifest.json file from the /public folder before the npm run build command is completed. It is best to add an option like --safe for the npm run build to keep the previous manifest.json until the command is executed. For example:

npm run build --safe
driesvints commented 7 months ago

This isn't something that would happen if you use different directories for building up a new version for app like Envoyer does. To see how you can do this with something like Envoy, have a look at the Spatie website Envoy file: https://github.com/spatie/spatie.be/blob/main/Envoy.blade.php

timacdonald commented 7 months ago

You will still run into missing asset issues if you do symlink deployments, such as those seen in the Spatie Envoy deploy script.

The best fix for this issue is to instruct vite to not empty the output directly by using the --emptyOutDir=false option to Vite.

npx vite build --emptyOutDir=false

Then at the end of your build script you may use our cleanup script to remove any files that are no longer needed. You should run this at the very end of your deployment script to ensure all active requests to your server for assets have completed. You might even consider putting a sleep in there to ensure the requests have finished...

npx vite build --emptyOutDir=false
sleep 1
npx clean-orphaned-assets
MohammadZarifiyan commented 7 months ago

You will still run into missing asset issues if you do symlink deployments, such as those seen in the Spatie Envoy deploy script.

The best fix for this issue is to instruct vite to not empty the output directly by using the --emptyOutDir=false option to Vite.

npx vite build --emptyOutDir=false

Then at the end of your build script you may use our cleanup script to remove any files that are no longer needed. You should run this at the very end of your deployment script to ensure all active requests to your server for assets have completed. You might even consider putting a sleep in there to ensure the requests have finished...

npx vite build --emptyOutDir=false
sleep 1
npx clean-orphaned-assets

npm ERR! code E404 npm ERR! 404 Not Found - GET https://registry.npmjs.org/clean-orphaned-assets - Not found npm ERR! 404 npm ERR! 404 'clean-orphaned-assets@*' is not in this registry. npm ERR! 404 npm ERR! 404 Note that you can also install from a npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2024-04-10T13_53_18_115Z-debug-0.log

timacdonald commented 7 months ago

What version of the plugin are you using? You will need 1.0 or greater.