Skip to content

fivethreeo/razzle-plugin-worker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

About

Razzle plugin to load workers using worker-loader.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published