https://github.com/webpack-contrib/worker-loader
inspired by[![npm][npm]][npm-url] [![node][node]][node-url] [![deps][deps]][deps-url] [![tests][tests]][tests-url] [![chat][chat]][chat-url] [![size][size]][size-url]
worker-url-loader
inline worker loader module for webpack
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 worker-url-loader
:
$ npm install worker-url-loader --save-dev
Inlined
// App.js;
Config
// webpack.config.js module: rules: test: /\.worker\.js$/ use: loader: 'worker-url-loader'
// App.js; const worker = WorkerUrl; worker;worker {}; worker; // or // const sharedWorker = new sharedWorker(WorkerUrl);// sharedWorker.port.start();
And run webpack
via your preferred method.
Examples
The worker file can import dependencies just like any other file:
// Worker.jsconst _ = const obj = foo: 'foo' _ // Post data to parent threadself // Respond to message from parent threadself
Integrating with ES2015 Modules
Note: You can even use ES2015 Modules if you have the
babel-loader
configured.
// Worker.js const obj = foo: 'foo' _ // Post data to parent threadself // Respond to message from parent threadself
Cross-Origin Policy
WebWorkers
are restricted by a
same-origin policy, so if
your webpack
assets are not being served from the same origin as your
application, their download may be blocked by your browser. This scenario can
commonly occur if you are hosting your assets under a CDN domain. Even downloads
from the webpack-dev-server
could be blocked. There are two workarounds:
Contributing
Please take a moment to read our contributing guidelines if you haven't yet done so.