GithubHelp home page GithubHelp logo

isabella232 / web-workers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vertexvis/web-workers

0.0 0.0 0.0 1.81 MB

A repository for creating and bundling web workers.

License: MIT License

Shell 26.12% JavaScript 16.88% TypeScript 55.88% HTML 1.12%

web-workers's Introduction

web-workers

This is a mono-repo that contains utilities to create and build web workers. It uses the Threads internally to handle the management of web workers and provide pooling behavior.

Packages

Package Version Description
@vertexvis/web-workers npm Package for defining and loading web workers.
@vertexvis/rollup-plugin-web-workers npm Package for building web workers with Rollup.

Simple Usage

See @vertexvis/web-workers for more advanced usage.

Worker

// ./worker.ts
import { defineWorker } from '@vertexvis/web-workers';

export type AddFn = (a: number, b: number) => Promise<number>;

const add: AddFn = async (a, b) => {
  return a + b;
}

defineWorker(add);

Entry

// ./main.ts
import type { AddFn } from './worker';
import { loadWorker } from 'worker:./worker';

async function main(): Promise<void> {
  const { spawnWorker } = await loadWorker<AddFn>();

  const add = await spawnWorker();
  const sum = await add(1, 2)
  console.log('sum', sum);
}

main();

Rollup Config

import resolve from '@rollup/plugin-node-resolve';
import typescript2 from 'rollup-plugin-typescript2';
import { terser } from 'rollup-plugin-terser';
import workers from '@vertexvis/rollup-plugin-web-workers';

export default {
  input: 'src/main.ts',
  output: {
    dir: './dist',
    format: 'esm',
  },
  plugins: [
    resolve(),
    workers({
      // Workers are bundled separately. Pass a list of plugins to use when
      // bundling the worker.
      plugins: [resolve(), typescript(), terser()]
    }),
    typescript2(),
  ]
}

Bumping Versions

The project's release scripts will automatically bump version based on the nextBumpVersion that's specified in the projects package.json file. When making a breaking change, you should run yarn version:bump and specify minor. This should be done as part of your PR.

Releasing

Run yarn release to create a release based on the nextBumpVersion that's specified in the projects package.json file. This field tracks if the next version should be a major, minor or patch release.

Run yarn release:ask to specify a custom release version.

These script will verify that your working directory is clean, is up-to-date with main, ask for the release version, generate documentation, and push a release branch to GitHub.

You can then create a PR from the release branch. Once your PR has been approved and merged, the CI pipeline will automatically publish packages to NPM, tag the release, and create a release in Github.

If the publishing, open a new PR with any fixes and merge your changes. CI will attempt to republish the previous release that failed.

web-workers's People

Contributors

dependabot[bot] avatar danschultz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.