Giter VIP home page Giter VIP logo

rollup-plugin-bundle-worker's Introduction

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'
};

rollup-plugin-bundle-worker's People

Contributors

andyearnshaw avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.