Hi!
What is the best approach to use libraries that require es modules, import maps or just have an npm install and no CDN? For example Three.js or @thatopen/components
Hi!
What is the best approach to use libraries that require es modules, import maps or just have an npm install and no CDN? For example Three.js or @thatopen/components
Hi @lars.bergh.hvidsten ,
To use modules without relying on a CDN, you have a couple of options. If the library is available via a CDN, you can technically use async import like this:
(async () => {
const THREE = await import('https://cdnjs.cloudflare.com/ajax/libs/three.js/0.169.0/three.cjs');
// Your code here
})();
If the module isn’t available on a CDN, you could consider bundling it into a file (e.g., using esbuild, webpack, or another bundler). You can then add this file as a Resource File in Create and use it as a standard resource in a Coded Component. This gives you more control and removes the dependency on an external CDN.
Hope this helps!
Thanks! I will test this out as soon as i have time