Closed newarifrh closed 1 year ago
Hi @newarifrh,
The @vite
directive needs to read the file into PHP and parse the JSON to determine the appropriate path for the requested asset(s). While it's possible to use file_get_contents
with a URL, making a network request for this probably isn't ideal and isn't supported.
You can see the code for fetching the manifest at https://github.com/laravel/framework/blob/c6e4fa8004cfee4eca3372fe89ee4fd66b97b56d/src/Illuminate/Foundation/Vite.php#L694-L726
You could extend this class, override some methods, and bind it in the container, but I wouldn't recommend it. Even with Laravel Vapor, we deploy the assets to a CDN but still read the manifest.json
file locally.
Thanks @jessarcher!
but at some point, the build on CDN and local is different. How to ensure the manifest.json in CDN and local is the same?
As long as your assets are deployed first and the assets from the previous deployment are kept around until after the deployment, it should be fine.
If an asset hasn't changed, it'll have the same hash in the file name. Otherwise, it will have a new hash. If you're copying them to the same directory then new and old assets can live together. You'd just need to figure out how you want to purge the old assets once you no longer need them.
I am also running into this issue at the moment.
The only way to actually get a manifest.json
file is to do a production run with vite using vite build
. I am currently performing this step on AWS codebuild so vite build
run in an isolated environment, pushes the files to S3 and then destroys that environment.
It wouldn't make sense to now also have to run vite build
on my production environment just create a manifest.json
file when all the files I actually need are already present in my S3 bucket. Especially since it doesn't just create the manifest but also all other files.
If I were to have a lot of EC2 instances on AWS they would all have a bunch of build files I don't need just to ensure that my manifest is there.
What is the workflow supposed to be for this? @jessarcher
@stephan-v with this setup you would also need to copy the built manifest.json
file to your servers or have them download the file on deploy.
You could also create an extended Vite
class that overrides the manifest*
methods to retrieve the manifest from your CDN. You'd likely want to cache it locally still though, so having it copied / downloaded as part of your deployment feels like the way to go IMO.
Vite Plugin Version
4.0.0
Laravel Version
10.10
Node Version
20.5.1
NPM Version
9.8.0
Operating System
Linux
OS Version
-
Web browser and version
-
Running in Sail?
No
Description
Hi, I created a Github Action to build my assets and deploy those assets to Digital Ocean. The assets are build and uploaded successfully, I've also set the ASSET_URL to the correct Digital Ocean. But the @vite blade directive seems still using the manifest.json from the original public folder, instead of from the ASSET_URL.
Dockerfile Laravel Project
Github Action Deploy Static Asset
Deploy Laravel Proejct to Server
Example view
Steps To Reproduce
npm run build