0

So I'm encountering this issue and I can't solve it so I thought post it here.

I found similar issues but those are about .css files and I'm dealing with images.

  1. Unable to locate file in Vite manifest: resources/css/app.css

  2. Unable to locate file in Vite manifest: resources/css/app.css.

  3. Larave & Vite - Vite manifest missing odd files

Here's my problem.

I ran npm run build and it was successful, the files are inside public/build/assets/ folder and the manifest.json is inside the public/build/ but I'm getting "Unable to locate file in Vite manifest: logo.png.

- public
  - build
    - assets
      - logo-7b466471.png
    - resources
      - index.html
    - manifest.json

The manifest.json has:

"resources/images/logo.png": {
  "file": "assets/logo-7b466471.png",
  "src": "resources/images/logo.png"
},

Here's how I use the image inside my blade.php file:

<img src="{{ Vite::asset('logo.png') }}">

In my app.js I have this at the very top:

import.meta.glob(["../images/**", "../fonts/**"]);

I have tried the solutions mention in the post.

EDIT:

I'm using the latest Laravel Framework: "laravel/framework": "^10.20.0"

My package.json:

"@vitejs/plugin-vue": "^4.3.3",
"laravel-vite-plugin": "^0.8.0",
"vite": "^4.4.9",
Uq Dke
  • 21
  • 3
  • Does this answer your question? [Laravel 9 - Vite is not bundling my images even if I declared the entry point](https://stackoverflow.com/questions/73582355/laravel-9-vite-is-not-bundling-my-images-even-if-i-declared-the-entry-point) – OMi Shah Aug 24 '23 at 05:57
  • Your image file location is ``resources/images/logo.png`` but you're referencing as only ``Vite::asset('logo.png')`` !!! – OMi Shah Aug 24 '23 at 05:58
  • My bad. Anyways I've solved the issue as provided in the answer below. – Uq Dke Aug 24 '23 at 06:11
  • lol ! Just because I used exclamation mark, it means I am shouting? Salute to you buddy! – OMi Shah Aug 24 '23 at 06:13
  • Salute to you too, buddy. – Uq Dke Aug 24 '23 at 06:15
  • and the way you solved, it's totally wrong. Think of like this: How would you reference a file residing in the following location: ``resources/clients/file.png``? It'll always point to ``resources/images/resources/clients/file.png`` since you modified the path. So you should not go with the solution you added. – OMi Shah Aug 24 '23 at 06:16
  • Just declare another `Vite` macro. Easy as that. Read the docs and you'll find out. EDIT: https://laravel.com/docs/10.x/vite#blade-processing-static-assets – Uq Dke Aug 24 '23 at 06:17
  • I am aware of that, that's just an another (a little longer) way of doing same but you have to repeat the process again when you can simply go with the simple solution, anyways your choice :) – OMi Shah Aug 24 '23 at 06:21

1 Answers1

1

Seems like no one has encountered this before.

I've solved it by doing the following:

  1. Make sure you're using Node 18.17 or higher.
  2. If you already run npm install delete the node_modules folder.
  3. Run npm install again.
  4. Run npm run build.
  5. In your app\Providers\AppServiceProvider.php add this line of code in the boot method.
use Illuminate\Support\Facades\Vite;

public function boot(): void
{
    Vite::macro('image', fn (string $asset) => $this->asset("resources/images/{$asset}"));
}
  1. In your blade file use the the Vite macro like this:
<img src="{{ Vite::image('logo.png') }}" />
  1. Lastly, in your vite.config.js add this:
export default defineConfig({
  build: {
    chunkSizeWarningLimit: 3072, // 3MB
    assetsInlineLimit: 0,
  },
  plugins: [
    // ...
  ],
});
OMi Shah
  • 5,768
  • 3
  • 25
  • 34
Uq Dke
  • 21
  • 3
  • 1
    Kindly, do not add comment(s) to your solution. That's not how we do on StackOverFlow. – OMi Shah Aug 24 '23 at 06:27
  • and the way you solved, it's totally wrong. Think of like this: How would you reference a file residing in the following location: resources/clients/file.png? It'll always point to resources/images/resources/clients/file.png since you modified the path. So you should not go with the solution you added. – OMi Shah There's nothing wrong with it as we can declare another macro. – Uq Dke Aug 24 '23 at 06:29
  • Carry on buddy. You seem totally off the track. – OMi Shah Aug 24 '23 at 06:30
  • Cheers buddy... – Uq Dke Aug 24 '23 at 06:31