-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Works in dev, build fails with Unknown variable dynamic import
#321
Comments
Hey, we've kind of solved this issue (partly) as follows:
const directives = {
imagecardPreview: new URLSearchParams(
'format=webp;jpg&width=438&height=250&position=entropy&quality=60&meta',
),
};
imagetools({
include: '**/*.{heic,heif,avif,jpeg,jpg,png,tiff,webp,gif}*',
defaultDirectives: (id) => {
// scan images without search params. These kind of images might be
// imported dynamically, where search params wont work.
if (id.search === '') {
if (id.pathname.includes('discretize-guides/guides/')) {
return directives.imagecardPreview;
}
}
return id.searchParams;
},
}) You don't add any search params to the imported picture at all, but instead do "the work" in the defaultDirectives. Maybe this piece of info could help you to create a solution for your problem? |
I believe this would potentially also be fixed by If this type of "query string in file import" path pattern is common, perhaps that would be a reasonable feature request for rollup/plugins? |
This is how Vite works and really isn't specific to imagetools at all. Vite can only handle static strings in imports and not dynamically constructed strings. Given that there isn't anything we can do about this in imagetools, I'm going to go ahead and close this |
Although I guess it's supposed to work in some cases: https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url. However, that case would be covered by #327, so I'll leave this closed in favor of that issue. |
I'm using
vite-imagetools
version4.0.3
with SvelteKit.This code...
...works as expected in dev mode, but build fails with error:
If I remove the query string from my import statement the build doesn't fail, but obviously any transformations don't take place.
The text was updated successfully, but these errors were encountered: