/spaceworker-loader

An easy way to use Webworker with promises in webpack

Primary LanguageJavaScriptMIT LicenseMIT

Spaceworker.js Webpack-loader

This is the Webpack loader for my simple libary to make it easier to use WebWorker called Spaceworker.js

Install

npm install --save-dev spaceworker-loader
OR
yarn add --dev spaceworker-loader

Usage

import '/spaceworker.js' into your html file :)

// app.js
const worker = require("./iss.worker.js")

worker.run("sayHelloWorld", "hello", "world")
    .then(res => {
        console.log(res) // hello world :)
    })
// iss.worker.js
class ISS {
    sayHelloWorld(hello, world) {
        return hello + " " + world + " :)"
    }
}

SpaceWorker.provide(ISS, self)
// webpack.config.js
const path = require('path')
const config = {
    entry: "./app.js",
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: "bundle.js"
    },
    module: {
        rules: [
            { test: /\.worker\.js$/, use: { loader: 'spaceworker-loader' } }
        ]
    }
}

module.exports = config