Module Workers Polyfill
This is a 1.1kb polyfill for Module Workers.
It adds support for new Worker('..',{type:'module'})
to all modern browsers (those that support fetch).
Usage
Copy module-workers-polyfill.js
to your web directory, then load it using an import or a script tag.
It just needs to be loaded before instantiating your Worker.
<script src="/module-workers-polyfill.js"></script>
<script>
const worker = new Worker('/worker.mjs', { type: 'module' });
</script>
Example
import '/module-workers-polyfill.js';
import importFromWorker from 'https://unpkg.com/import-from-worker@1.0.1/dist/import-from-worker.js';
function getAcornAST(code) {
const { parse } = await importFromWorker('https://unpkg.com/acorn@7.1.0/dist/acorn.mjs');
return await parse(code, { sourceType: 'module' });
}