Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JerryBels's avatar

Vite only importing some of the files in a folder

Hey guys, I'm migrating my Laravel app to Vite, and one of the things I wanted to do is copy over my images assets to the public folder. Following the Laravel doc https://laravel.com/docs/9.x/vite#blade-processing-static-assets I added import.meta.glob('../images/**'); to my app.js file, and ran the build command.

images

As you can see there are seven images in the folder. But the command outputted only 3 of them as imported, and sure enough when reloading one of the not imported images was missing : Unable to locate file in Vite manifest: images/local_icon.png.

did I miss something?

0 likes
12 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

I have seen this once before. In that case the image files had some extra information for using in an image editor. This made vite not see it as a web image and ignored it. Maybe try re-exporting the ones that aren't working

2 likes
JerryBels's avatar

Hello, thanks for helping. The thing is, if I select one of the other images manually and remove the wildcard, it is correctly imported. But if I let the wildcard up, only 2, 3 or 4 are imported. If I try to import them one by one, it imports some and ignores some, again. If I put all the names in an array, all the same. I really don't get it.

JerryBels's avatar

So what I ended up doing for now is creating a npm script "cpimages" : "rm -rf ./public/assets/images; cp -r ./resources/images ./public/assets" that I call when building "build": "npm run cpimages; vite build". My assets are available in my project, but not versionned by Vite. I can't think of anything else... If you guys got an idea please let me know.

Sinnbeck's avatar

@JerryBels I'll try recreating it. Also feel free to make a minimal reproducible example and put it on github

1 like
JerryBels's avatar

@Sinnbeck Yep, sure, here you go https://github.com/JerryBels/vite-image-bug

I added build folder to the versionned stuff so one can witness one image missing from built assets, comparing with resources/images.

One thing I tried is replacing all my images with images from Google and it worked. So I guess it has something to do with my images. I removed all personal metadata from them though.

Sinnbeck's avatar

@JerryBels It definitely has something to do with that production image. If I simply resize it, it starts working

JerryBels's avatar

@Sinnbeck Yes, I got that too, but as I said if I take the current production image and import only this one import.meta.glob('../images/production_icon.png'); it works. Also in other tries multiple images were missing (but I guess that can be because one is faulty then the process stops). Why?

Sinnbeck's avatar

@JerryBels Ah! That makes so much sense :) And awesome to see a laravel community member fix it

1 like
shibbirweb's avatar

At the first time I also thought that it was a bug from vite. but when I read their documentation I found this is a feature for Vite. If an asset file like (images) whose size is less than 4kb(Default size for vite) is marked as an inline element. and convert it into base64 format so that It loads without sending a request.

So when we use vite with Laravel we have to override this size. So simply we need this configuration.

export default defineConfig({
    build: {
        assetsInlineLimit: "2048", // 2kb, set as your minimum file size
    },
})

Documentation link: https://vitejs.dev/config/build-options.html#build-assetsinlinelimit

3 likes
JackySi's avatar

@shibbirweb Thank you for sharing. Solves my issue. And saves me a lot of time trying to find solution manually =)

Please or to participate in this conversation.