0.18.1 • Published 2 months ago

@chialab/esbuild-plugin-worker v0.18.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

How it works

Esbuild Plugin Worker looks for new Worker('./path/to/worker.js') statements in JavaScript and TypeScript files and instructs esbuild to treat that references as entrypoints. Final output will be used to correctly update the statement.

For example, the following script:

const worker = new Worker('./path/to/worker.js');

will be transformed to:

const worker = new Worker(new URL('./path/to/worker.js', import.meta.url));

and then resolved by the @chialab/esbuild-plugin-meta-url plugin.

Please note that RNA does not generate a Worker class to instantiate like webpack does, but it will just correctly update the import reference. If you need a Worker class, you have to wrap it yourself:

const workerClass = function() {
    return new Worker('./path/to/worker.js');
};

⚠️ At the moment this plugin does not collect importScript() statements and does treat workers as modules, but we have plan to support the { type: "module" } option in the near future.


Install

$ npm i @chialab/esbuild-plugin-worker -D
$ yarn add @chialab/esbuild-plugin-worker -D

Usage

import esbuild from 'esbuild';
import transfrom from '@chialab/esbuild-plugin-transform';
import workerPlugin from '@chialab/esbuild-plugin-worker';
import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';

await esbuild.build({
    plugins: [
        transfrom([
            workerPlugin(),
            metaUrlPlugin(),
        ]),
    ],
});

You can also define a list of Worker constructors to use (default it will look for Worker and SharedWorker):

workerPlugin({ constructors: ['Worker', 'MyWorker'] });

License

Esbuild Plugin Worker is released under the MIT license.

0.19.0-beta.0

2 months ago

0.18.1

2 months ago

0.18.0

4 months ago

0.18.0-alpha.1

8 months ago

0.17.5

11 months ago

0.18.0-alpha.0

1 year ago

0.17.4

1 year ago

0.17.3

2 years ago

0.17.2

2 years ago

0.17.0

2 years ago

0.17.1

2 years ago

0.15.39

2 years ago

0.15.37

2 years ago

0.15.38

2 years ago

0.16.0

2 years ago

0.16.1

2 years ago

0.16.2

2 years ago

0.15.20

2 years ago

0.15.23

2 years ago

0.15.28

2 years ago

0.15.17

2 years ago

0.15.6

2 years ago

0.15.9

2 years ago

0.15.14

2 years ago

0.15.15

2 years ago

0.15.16

2 years ago

0.15.4

2 years ago

0.15.0

2 years ago

0.15.2

2 years ago

0.15.3

2 years ago

0.14.11

2 years ago

0.14.10

2 years ago

0.14.17

2 years ago

0.14.15

2 years ago

0.14.19

2 years ago

0.13.13

2 years ago

0.15.0-alpha.1

2 years ago

0.14.0

2 years ago

0.14.1

2 years ago

0.14.2

2 years ago

0.14.3

2 years ago

0.14.4

2 years ago

0.13.8

2 years ago

0.12.39

2 years ago

0.13.0

2 years ago

0.13.2

2 years ago

0.13.11

2 years ago

0.12.34

3 years ago

0.12.31

3 years ago

0.12.11

3 years ago

0.12.19

3 years ago

0.12.12

3 years ago

0.12.15

3 years ago

0.12.22

3 years ago

0.12.24

3 years ago

0.12.26

3 years ago

0.12.7

3 years ago

0.12.9

3 years ago

0.12.2

3 years ago

0.12.3

3 years ago

0.12.0

3 years ago

0.11.39

3 years ago

0.11.38

3 years ago

0.11.37

3 years ago

0.11.35

3 years ago

0.11.36

3 years ago

0.11.34

3 years ago

0.11.32

3 years ago

0.11.26

3 years ago

0.11.28

3 years ago

0.11.29

3 years ago

0.11.25

3 years ago

0.11.19

3 years ago

0.11.8

3 years ago

0.11.9

3 years ago

0.11.10

3 years ago

0.11.11

3 years ago

0.11.13

3 years ago

0.11.5

3 years ago

0.11.4

3 years ago

0.11.2

3 years ago

0.11.0

3 years ago