ElMassimo / vite-plugin-image-presets

🖼 Image Presets for Vite.js apps
https://image-presets.netlify.app/
MIT License
250 stars 5 forks source link

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

Closed idank closed 1 year ago

idank commented 1 year ago

I have a "gallery" of images which gets loaded like so:

import.meta.glob<string>("@/assets/images/**", {
    eager: true,
    as: "url",
})

Is it possible to have the plugin process the images that get imported in this way? Thanks!

ElMassimo commented 1 year ago

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",
  import: 'default',
})