Giter VIP home page Giter VIP logo

Comments (9)

yamiteru avatar yamiteru commented on August 11, 2024 2

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.

from imagetools.

palle-k avatar palle-k commented on August 11, 2024 1

@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.

from imagetools.

benmccann avatar benmccann commented on August 11, 2024 1

@palle-k I think you'd want to use query for that: https://vitejs.dev/guide/features.html#custom-queries

from imagetools.

JonasKruckenberg avatar JonasKruckenberg commented on August 11, 2024

I'll try to see if this is possible once #17 is properly working, at least on next.
I don't know how Vite behaves when glob importing so I can make no promises but I definitely doesn't seem complicated

from imagetools.

JonasKruckenberg avatar JonasKruckenberg commented on August 11, 2024

Alright, I've been digging around a bit in the vitejs source code and it seems that they are passing the full url to fast-glob, so importing your example ./images/*.jpg?width=200;400&format=webp;jpg&meta Vite will try to match files in the asset directory with the pattern *.jpg?width=200;400&format=webp;jpg&meta which will obviously not match anything.

So it seems like for now glob imports unfortunately don't work, no. :/

from imagetools.

yamiteru avatar yamiteru commented on August 11, 2024

Thanks for investigating the issue.

That sucks.. because in several occasions dynamic import(${url}.jpg?webp) could not be resolved which means I have to import every image manually meaning having for example 10 image import statements at the beginning of one file.

from imagetools.

JonasKruckenberg avatar JonasKruckenberg commented on August 11, 2024

Yeah that's very annoying yeah.
Can you share a situation in which the glob import doesn't resolve?
Maybe we can work around that somehow!
Maybe it'd be worth it to raise it as an issue over at the vite repo. I'll try to to this tomorrow if I have the time πŸ‘πŸ»

from imagetools.

alphacornutum avatar alphacornutum commented on August 11, 2024

This I find is also a very good template: sveltejs/kit#241 (comment)

from imagetools.

benmccann avatar benmccann commented on August 11, 2024

I've added import.meta.glob to the docs and example to show how to use it

from imagetools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.