-
Notifications
You must be signed in to change notification settings - Fork 104
Open
Labels
Description
When bundling elk to be called not as a worker, but instead bundled as a larger codebase that is eventually used within a worker, elk has different export semantics and cannot be used whatsoever by the bundled code.
The culprit is this generated code:
if (typeof document === 'undefined' && typeof self !== 'undefined') {
var dispatcher = new Dispatcher(self);
self.onmessage = dispatcher.saveDispatch;
}
else if (typeof module !== 'undefined' && module.exports) {
Object.defineProperty(exports, '__esModule', {value:true});
module.exports = {'default':FakeWorker, Worker:FakeWorker};
}
Please, don't do this. To assume it's always meant to be run as a standalone worker just because it's within a worker context reduces modularity and re-usability, and just caused a good deal of headache.
The better approach would to be to generate two scripts - one that is the library and exports the same, always, and another that exports a worker wrapper around it.
Daniel-Khodabakhsh