Using web workers and babel in Meteor 1.4

I need to perform a heavy calculation client-side, which may takes 30-60 seconds. To avoid the browser locking up, I want to use web workers to do this.

Web workers rely on loading separate files. There are ways to “fake” this file (e.g. with http://npmjs.com/package/async-task, which in effect creates a file on the fly and wires it up as a web worker), or you could put a static file in public/.

However, this does not play well with the Meteor build system or babel. A file in public/ isn’t automatically built (I guess you’d want it to be a separate bundle), and using async-task I get strange errors that in effect relate to the fact that babel defines symbols when it transpiles down to ES5, which then aren’t available to the inner context of the function.

Any hints on how to make this work in a way that isn’t horrible (e.g. manually build an ES5 file without importing any modules/packages in public and load it explicitly in HTML)?

2 Likes