php
php copied to clipboard
Larvel 11 with assets, public/build files return 404
I am far from being a Laravel or Vercel expert, but it looks like the current Laravel example app is missing a few things when it comes to deploying the app on Vercel with assets (which are built with Vite).
The problem seems to be that the files from the build process are not available and cannot be requested (adding npm ci && npm run build to the composer.json scripts "vercel" does the build process perfectly):
public/build/assets/main-SWg09SIz.css 8.88 kB │ gzip: 2.55 kB
public/build/assets/app-BmrwFrBv.js
https://mydomain.com/build/assets/app-BmrwFrBv.js will result in a 404 no matter what i change in the vercel.json.
I tested several configurations in my vercel.json. It's also not clear to beginners like me when to use "functions" and when to use "builds."
"functions": {
"api/index.php": {
"runtime": "[email protected]"
}
},
"routes": [
{
"src": "/(favicon\\.ico|robots\\.txt)",
"dest": "/public/$1"
},
{
"src": "/build/(.*)",
"dest": "/public/build/$1"
},
{
"src": "/(.*)",
"dest": "/api/index.php"
}
]
I tested this: https://github.com/treckstar/vercel-laravel-10-starter/blob/main/vercel.json
and also this: https://github.com/juicyfx/vercel-examples/blob/master/php-laravel/vercel.json
(There is also a problem with HTTPS and the path to assets, but I fixed it by using an absolute path and the environment option ASSET_URL.)