-
-
Notifications
You must be signed in to change notification settings - Fork 184
Description
#1084 (comment) original comment but that issue is closed.
I know dynamic imports aren't supported, I won't ask for this but what I would like to ask is some kind of feature to ignore them or prevent errors from being thrown, similar to how this is possible in bundlers like Rollup, Webpack, Vite, etc.
Let's take the use case where certain libraries will dynamically import from resources such as a CDN.
For example:
const CDN_URL = `https://ga.jspm.io/npm:${package}@${version}/${entrypoint}`;
const mod = await import(CDN_URL);Bundlers in this case shouldn't even attempt to bundle the dynamic import, it doesn't need to analyze it and in the above example the CDN_URL variable isn't statically analyzable to begin with because it's a variable rather than a raw string.
Rollup will just ignore bundling such a dynamic import and give the user a warning, which in this case is desirable.
Webpack and Vite will error unless you wrap the import parameter in an ignore statement:
const CDN_URL = `https://ga.jspm.io/npm:${package}@${version}/${entrypoint}`;
const mod = await import(/* @vite-ignore */ /* webpackIgnore: true */ CDN_URL);I think it would be cool if shadow-cljs could add a way to ignore certain dynamic imports similar to Vite or Webpack, or at least some way to prevent it from throwing an error (e.g. in Rollup you can turn the warning off as well).
Even better of course if this bundler supports dynamic imports but until then this would already be a quick win for dynamic imports that are not intended to be analyzed by bundlers.
Originally posted by @jorenbroekema in #1084 (comment)