0.0.5 • Published 2 years ago

rollup-plugin-webworkify-fjo v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

rollup-plugin-webworkify-fjo

forked from rollup-plugin-webworkify

fix worker javascript-obfuscator bundle issues.

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.

inspired by webworkify

Install

yarn add rollup-plugin-webworkify -D

Require the plugin and add it to your configuration:

import webworkify from 'rollup-plugin-webworkify';

export default {
  entry: 'src/main.js',
  plugins: [
    webworkify({
      // specifically patten files
      pattern: '**/*.worker.js'  // Default: undefined (follow micromath globs)
    })
  ],
  format: 'umd'
};

Example

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

// import work from 'worker#../lib/worker.js'
import work from '../lib/foo.worker.js'

var w = new work
w.addEventListener('message', function (e) {
  console.log(e.data)
})

w.postMessage(4) // send the worker a message

then foo.worker.js, The worker function lives inside of the module.exports:

var gamma = require('gamma')

module.exports = function (self) {
  self.addEventListener('message',function (e) {
    var startNum = parseInt(e.data); // e.data=4 from main.js

    setInterval(function () {
      var r = startNum / Math.random() - 1
      self.postMessage([ startNum, r, gamma(r) ])
    }, 500)
  })
}
0.0.5

2 years ago

0.0.45

2 years ago

0.0.44

2 years ago

0.0.43

2 years ago

0.0.42

2 years ago

0.0.41

2 years ago

0.0.4

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago