question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support import.meta.glob

See original GitHub issue

It’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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
yamiterucommented, Mar 16, 2021

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.

1reaction
palle-kcommented, Jun 20, 2022

@JonasKruckenberg I had a look at the Vite source code and found that when using the as parameter in the import options, this should theoretically be forwarded to the import statement, e.g.:

const images = import.meta.globEager("./*.jpg", {as: "w=250"});

Link to Vite source

However, this does not seem to work in practice, transforms are not applied.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found