Support import.meta.glob
See original GitHub issueIt’d be awesome if we could leverage glob import to for example import all images in a directory AND apply transformations on all of them.
I image it’d be used just like this:
const images = import.meta.glob("./images/*.jpg?width=200;400&format=webp;jpg&meta");
The exported object might look like this:
{
"./images/01.jpg": {
"width=200&format=webp&meta": () => Promise<metadata>,
"width=200&format=jpg&meta": () => Promise<metadata>,
"width=400&format=webp&meta": () => Promise<metadata>,
"width=400&format=jpg&meta": () => Promise<metadata>
}
}
If we use globEager instead of glob we would get the metadata object instead of () => Promise<metadata>.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Features | Vite
Vite supports importing multiple modules from the file system via the special import.meta.glob function: js const modules = import.meta.glob('./dir/*.js').
Read more >[v3] Document type inference with import.meta.glob #9599
Describe the bug When using import.meta.glob with vite v3, no generic type is provided anymore. The JS Doc provides you with this ...
Read more >import.meta - JavaScript - MDN Web Docs
The import.meta meta-property exposes context-specific metadata to a JavaScript module. It contains information about the module, ...
Read more >Vite — Resolve `import.meta.glob` in TypeScript - Future Studio
Resolve Vite's import.meta.glob in TypeScript. Vite ships with TypeScript types and your editor or IDE should automatically resolve the types.
Read more >import.meta.glob() can only accept string literals - Stack Overflow
I was trying to do the same thing with Sveltekit. There's info at https://github.com/vitejs/vite/issues/5478. A quick workaround is to write ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve already deleted my prototype using dynamic imports. Tomorrow I’ll try to put together repo with imports that don’t resolve so we can eventually raise it as an issue at Vite.
@JonasKruckenberg I had a look at the Vite source code and found that when using the
asparameter in the import options, this should theoretically be forwarded to the import statement, e.g.:Link to Vite source
However, this does not seem to work in practice, transforms are not applied.