workers-loader
v2.1.2
Published
worker loader module for webpack
Downloads
21
Readme
workers-loader
Worker loader module for webpack
This fork of webpack-contrib/worker-loader add SharedWorker suport
Requirements
This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.
Getting Started
To begin, you'll need to install workers-loader
:
$ npm install workers-loader --save-dev
Inlined
// App.js
import Worker from 'worker-loader?shared!./Worker.js';
Config
// webpack.config.js
{
module: {
rules: [
{
test: /\.worker\.js$/,
use: { loader: 'workers-loader' }
}
]
}
}
// App.js
import Worker from './file.worker.js';
const worker = new Worker();
worker.postMessage({ a: 1 });
worker.onmessage = function (event) {};
worker.addEventListener("message", function (event) {});
And run webpack
via your preferred method.
Options
shared
Type: Boolean
Default: false
Create a SharedWorker
// webpack.config.js
{
loader: 'workers-loader'
options: { shared: true }
}
License
MIT
To see more options got to webpack-contrib/worker-loader