How to perform a “variable” ES6 import?

Not with the import statement. import and export are defined in such a way that they are statically analyzable, so they cannot depend on runtime information. You are looking for the loader API (polyfill), but I’m a bit unclear about the status of the specification: System.import(‘./utils/’ + variableName).then(function(m) { console.log(m); });

Is using an ES6 import to load specific names faster than importing a namespace?

TL;DR: It does not matter. import * as … from ‘ramda’; import { … } from ‘ramda’; will both by default always bring in the complete Ramda module with all its dependencies. All code inside the module would be run, and which syntax was used to reference the exported bindings doesn’t matter. Whether you use … Read more

Inlining ECMAScript Modules in HTML

Hacking Together Our Own import from ‘#id’ Exports/imports between inline scripts aren’t natively supported, but it was a fun exercise to hack together an implementation for my documents. Code-golfed down to a small block, I use it like this: <script type=”module” data-info=”https://stackoverflow.com/a/43834063″>let l,e,t=”script”,p=/(from\s+|import\s+)[‘”](#[\w\-]+)[‘”]/g,x=’textContent’,d=document, s,o;for(o of d.querySelectorAll(t+'[type=inline-module]’))l=d.createElement(t),o .id?l.id=o.id:0,l.type=”module”,l[x]=o[x].replace(p,(u,a,z)=>(e=d.querySelector( t+z+'[type=module][src]’))?a+`/* ${z} */’${e.src}’`:u),l.src=URL.createObjectURL (new Blob([l[x]],{type:’application/java’+t})),o.replaceWith(l)//inline</script> <script type=”inline-module” id=”utils”> … Read more