Let's say in my library I want to import an animation library only if the developer has installed it.
Pseudo code as follows:
let utility = null
// If the library returns the library location as a string
if (Boolean(require.resolve('animation-library'))) {
import('animation-library').then(library => utility = library.helper)
}
Currently, on Vite (Rollup.js) you get a warning, as the import is analyzed on compilation.
The above dynamic import cannot be analyzed by Vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/FfPtnER
Comments
Post a Comment