I've got a npm/webpack setup, and part of my application requires Web Workers. Normally, web workers are created with this syntax:
var worker = new Worker('path/to/external/js/file.js');
The worker-loader loader provided by Webpack seems to provide a solution to your problem. This module can be installed with
npm install --save-dev worker-loader.
Take a look at how to use loaders, then require your web worker files like so:
const Foo = require("worker!./path/to/external/js/file.js"); const fooWorker = new Foo();
worker! prepended before the path, which tells Webpack to use the worker loader specifically.
You should be able to require modules normally in the worker file itself also, provided your setup is correct.