JSFiddle - React, Tailwind, and code Playground
by Jason Miller
HTML
<script src="https://unpkg.com/workerize@0.1.8/dist/workerize.umd.js"></script>
JavaScript
function workerizeCjs(func) {
const w = workerize(func);
String(func).match(/\bexports\.[\w$]+/g).map(f=>w.expose(f.substr(8)));
return w;
}
const worker = workerizeCjs(function f(exports) {
exports.a = () => 1;
exports.b = () => 2;
});
worker.a().then(console.log) // 1
worker.b().then(console.log) // 2