1.0.4 • Published 6 years ago

razzle-plugin-worker v1.0.4

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

npm version

razzle-plugin-worker

Razzle plugin to load workers using worker-loader.

Usage in Razzle Projects

yarn add razzle-plugin-worker --dev

create a razzle.config.js file in root directory of project (next to the package.json) and put this content inside it

Using the plugin with the default options

// razzle.config.js

module.exports = {
  plugins: ['worker'],
};

Usage, any file loaded ending in .worker e.g. test.worker.js.

// test.worker.js
// Post data to parent thread
self.postMessage({ foo: 'foo' })

// Respond to message from parent thread
self.addEventListener('message', (event) => console.log(event))
// App.js
import './App.css';

if (process.env.BUILD_TARGET==='client') {

  const Worker = require('./test.worker');

  worker.postMessage({ a: 1 });
  worker.onmessage = function (event) {};

  worker.addEventListener("message", function (event) {});

}

import React from 'react';
const App = () => <div>Welcome to Razzle.</div>;

export default App;
1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago