This package has been deprecated

Author message:

All Cloud CNC projects have been deprecated!

threads-webpack-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

ThreadsJS Webpack integration

npm tests last commit

ThreadsJS integration for Webpack. If you're using Rollup, you may want to check out rollup-plugin-threads (Basically does the same thing as this plugin but for Rollup).

Features

  • Written in modern TypeScript
  • Uses Rollup for TS compilation
  • Thoroughly commented

Usage

Entry

//Imports
import {BlobWorker, spawn, Thread} from 'threads';
import WorkerText from './worker'; //May have to @ts-ignore if using TypeScript

//Create a **BLOB WORKER**
const worker = await spawn(BlobWorker.fromText(WorkerText));

console.log(worker.echo('Hello World!')); //Worker received: Hello World!

//Destroy the worker
Thread.terminate(worker);

Worker

//Imports
import {expose} from 'threads';

//Worker functions
const worker = {
  echo(input)
  {
    return `Worker received: ${input}`;
  }
};

//Expose worker
expose(worker);

Webpack Config

//Export
module.exports = {
  //Point at your normal file (The plugin will take care of loading the worker)
  entry: 'src/index.js',
  module: {
    rules: [
      {
        test: /worker\.js$/,
        loader: 'threads-webpack-plugin',
        options: {
          //Webpack child bundler options
        }
      }
    ]
  }
};

Package Sidebar

Install

npm i threads-webpack-plugin

Weekly Downloads

6

Version

1.1.0

License

MIT

Unpacked Size

7.58 kB

Total Files

8

Last publish

Collaborators

  • wakeful-cloud