Use Rollup with workers and ES6 modules today.
$ npm install --save @surma/rollup-plugin-off-main-thread
This plugin takes care of shimming module support in workers and allows you to use
OMT is the result of merging loadz0r and workz0r.
// rollup.config.js;input: "src/main.js"output:dir: "dist"// You _must_ use “amd” as your formatformat: "amd"plugins:;
I set up a gist to show a full setup with OMT.
// ...plugins: ;
loader: A string containing the EJS template for the amd loader. If
undefined, OMT will use
eval()to load dependencies instead of
importScripts(). This is not CSP compliant, but is required if you want to use dynamic imports in ServiceWorker.
workerRegexp: A RegExp to find
new Workers()calls. The second capture group must capture the provided file name without the quotes.
amdFunctionName: Function name to use instead of AMD’s
prependLoader: A function that determines whether the loader code should be prepended to a certain chunk. Should return true if the load is suppsoed to be prepended.