Be sure to reference the image with the vite helper in blade files https://laravel.com/docs/9.x/vite#blade-processing-static-assets
<img src="{{ Vite::asset('resources/image/logo.svg') }}">
Vite has no was of injecting the url itself
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello everyone !
I started a fresh Laravel 9 app and try viteJS to compile my assets.
I encounter a small problem to make my images appear via the img tag.
I read the doc to referencing my assets and specifically in the <img> tag.
I tried to do the same way as the doc, but despite that, after run npm run dev, my image does not appear. If I run npm run build, my image is not compiled in public folder.
So, here is my structure :
public/
resources/
├─ images/
│ ├─ logo.svg
And I'm referencing my image in blade this way :
<img src="../../images/logo.svg" width="312" height="80" />
I get a 404 error in the browser for the link http://myapp.test/images/logo.svg
However, in CSS, it works if I use a background-image: background-image: url('../images/logo.svg');
Do you have any idea where the issue might have come from? Here is my config :
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/scss/admin.scss',
],
refresh: true,
}),
],
resolve: {
alias: [
{
find: /^~(.*)$/,
replacement: '',
},
],
},
});
Thanks in advance for your help :)
@Vable I just noticed that you are not referencing your app.js file, so that might be the reeason
input: [
'resources/scss/admin.scss', //add app js as well, as that is where the import.meta is
],
Please or to participate in this conversation.