I am having trouble with paths in the development and production environments in a laravel/vue.js project.
In CSS files:
Development environment npm run hot only accepts absolute paths in urls like /public/images/image.png while the production environment npm run prod + php artisan serve only accepts relative paths like ../images/image.png.
When I try to use a relative path in vue the images are not shown in the browser and the console shows:
GET http://localhost:63342/images/image.png?ffda917d2a7141d8413f313bccf119c5 404 (Not Found)
In vue templates:
In order to being able to use inline images in production I had to wrap the path inside require().default:
<img :src="require('../images/image.png').default" class="emailIcon" alt="">
require() does not seem to work in the development environment though. When I npm run hot the images are not shown.
Browser console shows:
GET http://localhost:63342/images/image.png?ffda917d2a7141d8413f313bccf119c5 404 (Not Found)
specs:
Windows 10
Laravel: 8.55.0
Vue.js: 4.5.13
Edit:
From @Chandan's comment I found that <img src="images/image.png"> works for both environments IF the images folder is inside public.
Unfortunately this doesn't work for url("images/image.png") if you want to put an image as background. Any insight there?
Edit2:
In the end there was no good solution for my problem. So I stopped using npm run hot and instead linked npm run watch to php artisan serve. Now I'm only using production server with hot reload. You can see here how to set it up.