phplaraveliisvite

Issue with Vite in Production Environment on IIS Laravel


I need help with an issue in my production environment using Laravel and Vite. I've been struggling with this for days without success. Everything worked fine in development mode, and all assets loaded correctly. However, after switching to production mode (running the build command), Vite keeps trying to load assets from the local address.

The most common problems I'm encountering are:

Assets that should be loaded from the build folder are not found. Incorrect paths, like references to /resources/ instead of /build/. Attempts to access @vite/client, which is only used in development mode.

Updated the application URL in the .env file to reflect the production environment. Changed the hot file to point to the correct application address in production. Verified that the vite.config.js is configured with the server's IP address and the appropriate port. Ran both npm install and npm run build to ensure all dependencies are installed and assets are properly built. Environment: The application is hosted on IIS. Laravel with Vite is being used. The assets are generated in the public/build folder. Error: When I access the application, I receive 404 (Not Found) errors for resources that should be loaded from the build folder.

Has anyone faced a similar issue or knows how to fix this? Iā€™d greatly appreciate any help! šŸ˜Š


Solution

  • If your application is present on /public/build and the application requires /build then please define an http redirection (can be installed as an IIS component) such as:

    Redirect requests to destination: http://localhost/public/build

    Redirection Behavior: It should be modified is necessary according to your needs. Leave the two options blank for now.

    This redirection will redirect every request http://localhost/build/xyz to http://localhost/public/build/xyz. If the URL address or links in the page should not be seen by users as /public/build... then you may use more advanced URL Rewrite Module.