@gkatsev/rollup-plugin-bundle-worker
Bundles Worker code alongside your main code
Last updated 3 years ago by gkatsev .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @gkatsev/rollup-plugin-bundle-worker 
SYNC missed versions from official npm registry.

rollup-plugin-bundle-worker

Bundles a single JS file alongside your main source code as the source for a Web Worker. Provides a fallback for running the code in the main thread if the browser does not support creating Workers from blobs.

Getting started

npm install rollup-plugin-bundle-worker

Require the plugin and add it to your configuration:

import bundleWorker from 'rollup-plugin-bundle-worker';

export default {
    entry: 'src/main.js',
    plugins: [ bundleWorker() ],
    format: 'umd'
};

For each worker that you want to create, import the file with a worker! prefix:

import MyWorker from 'worker!./my-worker.js';

var myWorker = new MyWorker();
myWorker.onmessage = function (evt) {
    if (evt.data === 'hello') {
        myWorker.postMessage('hello back!');
    }
};

Usage with Babel

The plugin allows your worker scripts to be transformed by the babel plugin. However, if you specify your preset as a string in the configuration, you will receive an error that the preset cannot be found for the worker file. Instead, you should manually require the preset and pass it to the Babel configuration:

import bundleWorker from 'rollup-plugin-bundle-worker';
import babel from 'rollup-plugin-babel';
import preset2015 from 'babel-preset-es2015-rollup';

export default {
    entry: 'src/main.js',
    plugins: [ bundleWorker(), babel({ presets: [ preset2015 ]}) ],
    format: 'umd'
};

Current Tags

  • 1.0.2                                ...           latest (3 years ago)

3 Versions

  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 21
Last Day 0
Last Week 12
Last Month 10
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |