Skip to content

Can this work with import.meta.glob? #23

Answered by ElMassimo
idank asked this question in Q&A
Discussion options

You must be logged in to vote

In Vite 2 there was no way to pass "parameters" to glob imports.

However, in Vite 4, it's now possible to use as to provide the parameters, and this works as expected:

import type { ImageAttrs } from 'vite-plugin-image-presets'

const images = import.meta.glob<ImageAttrs[]>("@/assets/images/**", {
  eager: true,
  as: "preset=default", // use whatever preset you want
  import: 'default', // to simplify "unwrapping" the imports
})

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@idank
Comment options

@ElMassimo
Comment options

@idank
Comment options

Answer selected by ElMassimo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #22 on March 29, 2023 13:33.