humaans / next-img

A Next.js plugin for embedding optimized images.
https://humaans.github.io/next-img/
273 stars 11 forks source link

How to handle dynamic imports #19

Open iDVB opened 1 year ago

iDVB commented 1 year ago

Question: How should we handle dynamically importing in a directory of images?

Eg. This first one would fail, where the second one would succeed.

  const stuff = "tree.jpg";
  const stuff2 = "?sizes=375";

   return (<Picture
        src={[
          require(`../assets/images/${stuff}${stuff2}`),
          require(`../assets/images/${stuff}`),
        ]}
        breakpoints={[768]}
      />)