Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/worker-pack
Run web workers from a single browserified bundle.
https://github.com/hughsk/worker-pack
Last synced: 8 days ago
JSON representation
Run web workers from a single browserified bundle.
- Host: GitHub
- URL: https://github.com/hughsk/worker-pack
- Owner: hughsk
- License: other
- Created: 2013-06-16T17:23:07.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-06-16T17:33:33.000Z (over 11 years ago)
- Last Synced: 2024-10-17T16:38:06.129Z (22 days ago)
- Language: JavaScript
- Size: 105 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# worker-pack #
A quick and dirty way of running Web Workers within a single
[browserified](http://browserify.org/) bundle.Intended as a solution that works now, avoiding any significant tradeoffs
(e.g. duplicate scripts). Here's hoping it gets rendered obsolete by
[workerify](https://github.com/shama/workerify) if/when Browserify's transform
API gets a little bit more flexible.## Installation ##
``` bash
npm install worker-pack
```## Usage ##
Firstly, though worker-pack is intended for Browserify v2 it isn't packaged as
a transform stream. Instead, you just have to pipe Browserify's output through
the worker-pack CLI:``` bash
# Instead of this:
browserify index.js > bundle.js
# Do this:
browserify index.js | node_modules/.bin/worker-pack > bundle.js
```Now you should be able to `require('worker-pack')` from `index.js`:
``` javascript
var pack = require('worker-pack')if (pack.isWorker()) {
self.onmessage = function() { self.postMessage('beep boop') }
} else {
var worker = pack.createWorker()
worker.onmessage = function(e) { console.log(e.data) }
worker.postMessage()
}
```If you want to use the [workerstream](http://npmjs.org/package/workerstream)
module, you can just get a Worker URL and pass that to the stream:``` javascript
var workerstream = require('workerstream')
, pack = require('worker-pack')if (!pack.isWorker()) {
var worker = workerstream(pack.createWorkerURL())
}
```