Skip to main content
Laravel Applications

Fix Laravel Vite Assets Loading from Development Server in Production

Fix Laravel Vite Assets Loading from Development Server in Production – Complete Guide Deploying a Laravel application with Vite can sometimes throw u...

Engr Mejba Ahmed
Author
Engr Mejba Ahmed
Published
Oct 03, 2025
Reading time
4 min · 723 words
Fix Laravel Vite Assets Loading from Development Server in Production
Featured image for Fix Laravel Vite Assets Loading from Development Server in Production

Fix Laravel Vite Assets Loading from Development Server in Production – Complete Guide

Deploying a Laravel application with Vite can sometimes throw unexpected issues. One of the most common headaches is when your production site tries to load assets from localhost:5173, instead of the compiled files from /public/build.

If your site is breaking in production because of this, don’t worry — this guide provides a real-world fix tested in multiple deployments. By the end, you’ll not only solve the issue but also set up a reliable workflow that ensures it never happens again.


Understanding the Problem

When working locally, Laravel with Vite uses a hot module replacement (HMR) server running at http://localhost:5173. This makes development fast and efficient, with instant browser updates.

But here’s the catch:

  • In production, your server doesn’t run this dev server.
  • Instead, it should serve the pre-built assets inside /public/build.
  • If you see references like this in production:
<link rel="stylesheet" href="http://localhost:5173/resources/css/app.css">

instead of:

<link rel="stylesheet" href="https://yourdomain.com/build/assets/app-xxxx.css">

…it means Laravel is still trying to use the hot reload dev server.

The culprit? 👉 A leftover public/hot file that tells Laravel to keep using localhost:5173.


Quick Fix for Production

Run these commands on your production server:

cd /home/username/public_html
rm -f public/hot
php artisan config:clear
php artisan cache:clear
php artisan view:clear

✅ This removes the hot file and clears Laravel caches. ✅ Once done, reload your site — it should immediately use the compiled assets.


Permanent Fix with Deployment Workflow

Manually fixing is fine once. But if you deploy often, you want automation.

Step 1 – Update .gitignore

Make sure public/build is not ignored, since you need compiled assets in production:

# Keep build folder in repo
!public/build

Step 2 – Always Build Locally

Since your production server doesn’t have npm, build assets before pushing:

npm run build
git add .
git commit -m "Build assets for production"
git push origin main

Step 3 – GitHub Actions for Deployment

Update your GitHub Actions workflow to:

  • Deploy code
  • Remove public/hot
  • Clear caches

Example workflow snippet:

- name: Remove hot file
  run: rm -f public/hot

- name: Clear Laravel caches
  run: |
    php artisan config:clear
    php artisan cache:clear
    php artisan view:clear

Best Practices – Do’s & Don’ts

Do:

  • Run npm run build before deploying
  • Commit /public/build into your repo
  • Automate cache clearing

Don’t:

  • Run npm run dev on production
  • Commit public/hot
  • Forget to build before pushing

Typical Deployment Workflow

Here’s what your development → production cycle should look like:

# Local development
npm run dev  

# Before deploy
npm run build  
git add .  
git commit -m "Production build"  
git push origin main  

Your CI/CD pipeline (GitHub Actions, Forge, etc.) will handle the rest.


Real-World Buyer Outcomes

By fixing this issue, buyers (your clients) get:

  • A fully working production site without broken CSS/JS.
  • Confidence that deployments won’t break again.
  • Optimized workflow for Laravel + Vite projects.
  • Reduced downtime, which directly impacts user experience and conversions.

This builds trust in your expertise and ensures repeat clients.


FAQs

Q1: Why is Laravel loading assets from localhost:5173 in production? Because the public/hot file still exists, making Laravel think it should use the dev server.

Q2: Can I fix this without GitHub Actions? Yes. Manually delete public/hot and rebuild assets locally before deploying.

Q3: Do I need to commit /public/build? Yes, since your production server may not have Node/NPM.

Q4: What if I use Laravel Forge or Vapor? Same process applies — always build assets locally and commit /public/build.

Q5: Should I ever run npm run dev in production? No, it’s only for local development. Use npm run build for production.

Q6: How do I know it’s fixed? Check your production HTML source. If asset URLs load from /build/assets/… instead of localhost:5173, you’re good!


Conclusion

Fixing Laravel Vite assets loading from development server in production is straightforward once you know the root cause — the public/hot file. With the quick fix and a robust deployment workflow, you’ll ensure production deployments always load the correct compiled assets.

This not only solves the immediate problem but also gives you a future-proof process that builds client trust and keeps production environments stable.

Engr Mejba Ahmed

About the author

Engr Mejba Ahmed

I'm Engr. Mejba Ahmed, a Software Engineer, Cybersecurity Engineer, and Cloud DevOps Engineer specializing in Laravel, Python, WordPress, cybersecurity, and cloud infrastructure. Passionate about innovation, AI, and automation.

Tags

Keep reading

Browse the blog →