vite-plugin / vite-plugin-dynamic-import

Enhance Vite builtin dynamic import
https://www.npmjs.com/package/vite-plugin-dynamic-import
MIT License
193 stars 11 forks source link

Dynamic import check removes dynamic import code before check #74

Closed WilliamTomOBrien closed 2 months ago

WilliamTomOBrien commented 5 months ago

The check to determine if code has a dynamic import has a small issue with regards to how it handles comments. Within the code:

const message = "//"; var module = await import(`./name-of-module-${variable}.js`);

the regex will remove everything after the //, despite it being valid javascript. (Example)

In libraries that have previously been minified, it is likely for multiple lines of code to be placed on the same line. This especially becomes an issue when code has strings containing URLs, and/or base64 encoded images, both of which are likely to contain // without actually signifying a comment, and thus could possibly remove large chunks of code that should still be checked.