Use importmaps in a worker interface
npm install worker-with-import-map``sh`
npm i worker-with-import-map
See https://github.com/WICG/import-maps/issues/2
1) WorkerWithImportMapViaInlineFrame: Enabling importmaps in web workers via iframes as workers.
2) WorkerWithImportMapViaBedfordsShim: Same polyfill idea, but using @guybedford's ESM shim inside a normal Worker.
test.html
`html`
test.js
`js`
import {Worker} from 'worker-with-import-map';
const worker = new Worker('./worker-script.js');
worker.postMessage({hello: 'ping'});
worker-script.js
`js`
// Here you can import anything you want now with import map support!
import {funny} from 'one-of-your-fancy-libs';
self.onmessage = (e) => {
const haiToo = funny('pong');
self.postMessage({haiToo});
}
This works in client and server, buildless (aka no build tools like rollup or Webpack` required).
Please just clone this repo and test:
- http://127.0.0.1/worker-with-import-map/test/test.html
That will give you a better picture with non-trivial code and showing off how you can re-use your importmap too.
Just test it and report feedback, if you feel like it.
Fun!