Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analysis of size param in require doesn't work with variables #156

Open
albertpeiro opened this issue May 12, 2020 · 1 comment
Open

Analysis of size param in require doesn't work with variables #156

albertpeiro opened this issue May 12, 2020 · 1 comment

Comments

@albertpeiro
Copy link

This works:

const Picture = ({ path, srcSizes, ...props }: PictureProps) => {
  return (
    <picture>
      {srcSizes &&
        srcSizes.map((size, index) => (
          <source
            key={index}
            media={`(max-width: ${size}`}
            srcSet={require(`~/images/${path}?&webp`)}
            type="image/webp"
          />
        ))}
      {/* 
      <source srcSet={require(`~/images/${path}`)} type="image/jpeg" /> */}
      <img src={require(`~/images/${path}?`)} {...props} />
    </picture>
  );
};

but using size param doesn't work (and it's installed and works otherwise outside the map):

<source
            key={index}
            media={`(max-width: ${size}`}
            srcSet={require(`~/images/${path}?size=${size}&webp`)}
            type="image/webp"
          />

More tests...

this works:

const sources = srcSizes.map((size) =>
    require("~/images/" + path + "?size=" + 48 + "&webp")
  );

but this doesn't work:

const sources = srcSizes.map((size) =>
    require("~/images/" + path + "?size=" + size + "&webp")
  );

Error:
Screenshot 2020-05-12 at 19 40 31

@albertpeiro
Copy link
Author

This is not an issue with this repo, but I guess this repo could work around it.
here's the limitation:
webpack/webpack#2992

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant