Use Rollup with workers and ES6 modules today.
$ npm install --save @surma/rollup-plugin-off-main-thread
Workers are JavaScript’s version of threads. Workers are important to use as the main thread is already overloaded, especially on slower or older devices.
This plugin takes care of shimming module support in workers and allows you to use new Worker()
.
OMT is the result of merging loadz0r and workz0r.
// rollup.config.js
import OMT from "@surma/rollup-plugin-off-main-thread";
export default {
input: ["src/main.js"],
output: {
dir: "dist",
// You _must_ use “amd” as your format
format: "amd"
},
plugins: [OMT()]
};
I set up a gist to show a full setup with OMT.
{
// ...
plugins: [OMT(options)];
}
loader
: A string containing the EJS template for the amd loader. Ifundefined
, OMT will useloader.ejs
.useEval
: Usefetch()
+eval()
to load dependencies instead of<script>
tags andimportScripts()
. This is not CSP compliant, but is required if you want to use dynamic imports in ServiceWorker.workerRegexp
: A RegExp to findnew Workers()
calls. The second capture group must capture the provided file name without the quotes.amdFunctionName
: Function name to use instead of AMD’sdefine
.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.
License Apache-2.0