JSPM

module-workers-polyfill

0.3.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 825
  • Score
    100M100P100Q102473F
  • License Apache-2.0

Package Exports

  • module-workers-polyfill

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (module-workers-polyfill) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Module Workers Polyfill npm version

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

// load the polyfill:
import '/module-workers-polyfill.js';

// now we can use import-from-worker, which relies on Module Workers:
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' });
}