How to bundled URL import "esm.sh/..." like any other normal imports? #20014
-
If im use an URL import like this: vite wont bundle it and will require to GET on runtime. So, is there a way to bundled it? maybe a plugin? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, you'll need to use a plugin to swap out the import specifiers for the CDN content (which you can simply use It's not the most minimal example, but we do something like this to power Preact's REPL on our doc site. It's not much code, and is fairly well-documented, so it might be of use to reference: https://github.com/preactjs/preact-www/blob/d5e1eac9bae7d5f23fa071d0063851b7d4accd7b/src/components/controllers/repl/repl.worker.js#L85-L131 |
Beta Was this translation helpful? Give feedback.
Yes, you'll need to use a plugin to swap out the import specifiers for the CDN content (which you can simply use
fetch
to get).It's not the most minimal example, but we do something like this to power Preact's REPL on our doc site. It's not much code, and is fairly well-documented, so it might be of use to reference: https://github.com/preactjs/preact-www/blob/d5e1eac9bae7d5f23fa071d0063851b7d4accd7b/src/components/controllers/repl/repl.worker.js#L85-L131