Dynamic import, but where the module you import runs in a different thread.
Powered by Comlink and Module Workers.
Available via unpkg: https://unpkg.com/comlinkage
Here's roughly the source for a demo where we're running Acorn in a Worker. You can view the full demo on Glitch.
import importFromWorker from 'https://unpkg.com/comlinkage';
const { parse } = importFromWorker('https://unpkg.com/[email protected]/dist/acorn.mjs');
class ShowAst extends HTMLElement {
attachedCallback() {
const parsed = await parse(this.textContent, { sourceType: 'module' });
this.textContent = JSON.stringify(parsed, 0, 2);
}
}
customElements.define('show-ast', ShowAst);