@trickfilm400/rollup-plugin-off-main-thread 2.4.3 → 3.0.0-pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +8 -8
- package/CONTRIBUTING +27 -27
- package/CONTRIBUTORS +11 -11
- package/LICENSE +202 -202
- package/README.md +97 -97
- package/index.js +318 -318
- package/karma.conf.js +46 -46
- package/loader.ejs +76 -76
- package/package.json +42 -42
- package/run_tests.js +105 -105
- package/tests/amd-function-name.test.js +33 -33
- package/tests/asset-in-worker.test.js +33 -33
- package/tests/dynamic-import.test.js +33 -33
- package/tests/fixtures/amd-function-name/a.js +16 -16
- package/tests/fixtures/amd-function-name/build/a-29701bae.js +22 -0
- package/tests/fixtures/amd-function-name/build/a-REsyh-LW.js +22 -0
- package/tests/fixtures/amd-function-name/build/a-bd62e735.js +22 -0
- package/tests/fixtures/amd-function-name/build/entry.js +95 -0
- package/tests/fixtures/amd-function-name/build/runner.html +15 -15
- package/tests/fixtures/amd-function-name/config.json +3 -3
- package/tests/fixtures/amd-function-name/entry.js +22 -22
- package/tests/fixtures/assets-in-worker/build/assets/my-asset-8db90352.bin +1 -0
- package/tests/fixtures/assets-in-worker/build/assets/my-asset-C4yNwep_.bin +1 -0
- package/tests/fixtures/assets-in-worker/build/entry.js +90 -0
- package/tests/fixtures/assets-in-worker/build/runner.html +15 -15
- package/tests/fixtures/assets-in-worker/build/worker-2a7f7c23.js +91 -0
- package/tests/fixtures/assets-in-worker/build/worker-5cc2068a.js +92 -0
- package/tests/fixtures/assets-in-worker/build/worker-CtBAebZB.js +92 -0
- package/tests/fixtures/assets-in-worker/entry.js +17 -17
- package/tests/fixtures/assets-in-worker/rollup.config.js +25 -25
- package/tests/fixtures/assets-in-worker/worker.js +18 -18
- package/tests/fixtures/dynamic-import/a.js +16 -16
- package/tests/fixtures/dynamic-import/build/a-Dqjf2iqw.js +22 -0
- package/tests/fixtures/dynamic-import/build/a-b9a1bf8d.js +22 -0
- package/tests/fixtures/dynamic-import/build/a-f1483003.js +22 -0
- package/tests/fixtures/dynamic-import/build/entry.js +87 -0
- package/tests/fixtures/dynamic-import/build/runner.html +15 -15
- package/tests/fixtures/dynamic-import/entry.js +14 -14
- package/tests/fixtures/import-meta/a.js +16 -16
- package/tests/fixtures/import-meta/build/a-115d949a.js +22 -0
- package/tests/fixtures/import-meta/build/a-550898d2.js +22 -0
- package/tests/fixtures/import-meta/build/a-BFYklafB.js +22 -0
- package/tests/fixtures/import-meta/build/entry.js +87 -0
- package/tests/fixtures/import-meta/build/runner.html +15 -15
- package/tests/fixtures/import-meta/entry.js +14 -14
- package/tests/fixtures/import-meta-worker/a.js +12 -12
- package/tests/fixtures/import-meta-worker/build/a-23c670a1.js +83 -0
- package/tests/fixtures/import-meta-worker/build/a-9c89b629.js +85 -0
- package/tests/fixtures/import-meta-worker/build/a-CrtsJ3Po.js +83 -0
- package/tests/fixtures/import-meta-worker/build/a-e0498c05.js +83 -0
- package/tests/fixtures/import-meta-worker/build/entry.js +94 -0
- package/tests/fixtures/import-meta-worker/build/runner.html +15 -15
- package/tests/fixtures/import-meta-worker/entry.js +22 -22
- package/tests/fixtures/import-worker-url/a.js +16 -16
- package/tests/fixtures/import-worker-url/b.js +16 -16
- package/tests/fixtures/import-worker-url/build/b-64a9d830.js +22 -0
- package/tests/fixtures/import-worker-url/build/b-725e92c1.js +5 -0
- package/tests/fixtures/import-worker-url/build/entry.js +95 -0
- package/tests/fixtures/import-worker-url/build/runner.html +15 -15
- package/tests/fixtures/import-worker-url/build/worker-Bq6uP7t8.js +123 -0
- package/tests/fixtures/import-worker-url/build/worker-ef1d7c89.js +106 -0
- package/tests/fixtures/import-worker-url/build/worker-f5690442.js +105 -0
- package/tests/fixtures/import-worker-url/entry.js +21 -21
- package/tests/fixtures/import-worker-url/worker.js +17 -17
- package/tests/fixtures/import-worker-url-custom-scheme/a.js +16 -16
- package/tests/fixtures/import-worker-url-custom-scheme/b.js +16 -16
- package/tests/fixtures/import-worker-url-custom-scheme/build/b-725e92c1.js +5 -0
- package/tests/fixtures/import-worker-url-custom-scheme/build/b-74a80c25.js +22 -0
- package/tests/fixtures/import-worker-url-custom-scheme/build/entry.js +95 -0
- package/tests/fixtures/import-worker-url-custom-scheme/build/runner.html +15 -15
- package/tests/fixtures/import-worker-url-custom-scheme/build/worker-Bq6uP7t8.js +123 -0
- package/tests/fixtures/import-worker-url-custom-scheme/build/worker-e37d535c.js +105 -0
- package/tests/fixtures/import-worker-url-custom-scheme/build/worker-ef1d7c89.js +106 -0
- package/tests/fixtures/import-worker-url-custom-scheme/config.json +3 -3
- package/tests/fixtures/import-worker-url-custom-scheme/entry.js +21 -21
- package/tests/fixtures/import-worker-url-custom-scheme/worker.js +17 -17
- package/tests/fixtures/module-worker/a.js +20 -20
- package/tests/fixtures/module-worker/b.js +20 -20
- package/tests/fixtures/module-worker/build/b-8d8ba280.js +20 -0
- package/tests/fixtures/module-worker/build/b-ZxqdL95j.js +21 -0
- package/tests/fixtures/module-worker/build/b-f6cfc895.js +21 -0
- package/tests/fixtures/module-worker/build/entry.js +17 -0
- package/tests/fixtures/module-worker/build/runner.html +15 -15
- package/tests/fixtures/module-worker/build/worker-41a1c649.js +1 -0
- package/tests/fixtures/module-worker/build/worker-50885fe8.js +38 -0
- package/tests/fixtures/module-worker/build/worker-9fb0618d.js +39 -0
- package/tests/fixtures/module-worker/build/worker-DWbjHYfx.js +39 -0
- package/tests/fixtures/module-worker/entry.js +17 -17
- package/tests/fixtures/module-worker/rollup.config.js +4 -4
- package/tests/fixtures/module-worker/worker.js +17 -17
- package/tests/fixtures/more-workers/a.js +16 -16
- package/tests/fixtures/more-workers/b.js +16 -16
- package/tests/fixtures/more-workers/build/b-Dok_VKGN.js +22 -0
- package/tests/fixtures/more-workers/build/b-e9bb9f94.js +22 -0
- package/tests/fixtures/more-workers/build/b-f31d0f9f.js +22 -0
- package/tests/fixtures/more-workers/build/entry.js +107 -0
- package/tests/fixtures/more-workers/build/runner.html +15 -15
- package/tests/fixtures/more-workers/build/worker_a-25924b0d.js +105 -0
- package/tests/fixtures/more-workers/build/worker_a-DtsyxKtN.js +105 -0
- package/tests/fixtures/more-workers/build/worker_a-b8e0ca8d.js +104 -0
- package/tests/fixtures/more-workers/build/worker_b-477edb2c.js +91 -0
- package/tests/fixtures/more-workers/build/worker_b-60981e1f.js +91 -0
- package/tests/fixtures/more-workers/build/worker_b-CG60Lcld.js +91 -0
- package/tests/fixtures/more-workers/entry.js +34 -34
- package/tests/fixtures/more-workers/worker_a.js +16 -16
- package/tests/fixtures/more-workers/worker_b.js +18 -18
- package/tests/fixtures/public-path/a.js +16 -16
- package/tests/fixtures/public-path/build/a-1fb502b9.js +22 -0
- package/tests/fixtures/public-path/build/a-Dqjf2iqw.js +22 -0
- package/tests/fixtures/public-path/build/a-b9a1bf8d.js +22 -0
- package/tests/fixtures/public-path/build/entry.js +87 -0
- package/tests/fixtures/public-path/build/runner.html +15 -15
- package/tests/fixtures/public-path/config.json +3 -3
- package/tests/fixtures/public-path/entry.js +14 -14
- package/tests/fixtures/simple-bundle/a.js +16 -16
- package/tests/fixtures/simple-bundle/build/entry.js +105 -0
- package/tests/fixtures/simple-bundle/build/runner.html +15 -15
- package/tests/fixtures/simple-bundle/entry.js +16 -16
- package/tests/fixtures/single-default/a.js +14 -14
- package/tests/fixtures/single-default/build/entry.js +103 -0
- package/tests/fixtures/single-default/build/runner.html +15 -15
- package/tests/fixtures/single-default/entry.js +16 -16
- package/tests/fixtures/url-import-meta-worker/a.js +17 -17
- package/tests/fixtures/url-import-meta-worker/b.js +16 -16
- package/tests/fixtures/url-import-meta-worker/build/b-258f8a6b.js +22 -0
- package/tests/fixtures/url-import-meta-worker/build/b-8c5ed926.js +22 -0
- package/tests/fixtures/url-import-meta-worker/build/b-CNJP1XvI.js +22 -0
- package/tests/fixtures/url-import-meta-worker/build/entry.js +91 -0
- package/tests/fixtures/url-import-meta-worker/build/runner.html +15 -15
- package/tests/fixtures/url-import-meta-worker/build/worker-9a661671.js +105 -0
- package/tests/fixtures/url-import-meta-worker/build/worker-S2Vh56Q-.js +106 -0
- package/tests/fixtures/url-import-meta-worker/build/worker-e833ae5d.js +106 -0
- package/tests/fixtures/url-import-meta-worker/entry.js +20 -20
- package/tests/fixtures/url-import-meta-worker/worker.js +16 -16
- package/tests/fixtures/worker/a.js +17 -17
- package/tests/fixtures/worker/b.js +16 -16
- package/tests/fixtures/worker/build/b-258f8a6b.js +22 -0
- package/tests/fixtures/worker/build/b-CNJP1XvI.js +22 -0
- package/tests/fixtures/worker/build/b-a9f43d76.js +22 -0
- package/tests/fixtures/worker/build/entry.js +91 -0
- package/tests/fixtures/worker/build/runner.html +15 -15
- package/tests/fixtures/worker/build/worker-S2Vh56Q-.js +106 -0
- package/tests/fixtures/worker/build/worker-b4897a54.js +105 -0
- package/tests/fixtures/worker/build/worker-e833ae5d.js +106 -0
- package/tests/fixtures/worker/entry.js +18 -18
- package/tests/fixtures/worker/worker.js +16 -16
- package/tests/import-meta-worker.test.js +37 -37
- package/tests/import-meta.test.js +33 -33
- package/tests/import-worker-url-custom-scheme.test.js +42 -42
- package/tests/import-worker-url.test.js +41 -41
- package/tests/module-worker.test.js +47 -47
- package/tests/more-workers.test.js +33 -33
- package/tests/public-path.test.js +33 -33
- package/tests/simple-bundle.test.js +33 -33
- package/tests/single-default.test.js +33 -33
- package/tests/url-import-meta-worker.test.js +34 -34
- package/tests/worker.test.js +33 -33
package/README.md
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
# rollup-plugin-off-main-thread
|
|
2
|
-
|
|
3
|
-
Use Rollup with workers and ES6 modules _today_.
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
$ npm install --save @trickfilm400/rollup-plugin-off-main-thread
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
Workers are JavaScript’s version of threads. [Workers are important to use][when workers] as the main thread is already overloaded, especially on slower or older devices.
|
|
10
|
-
|
|
11
|
-
This plugin takes care of shimming module support in workers and allows you to use `new Worker()`.
|
|
12
|
-
|
|
13
|
-
OMT is the result of merging loadz0r and workz0r.
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
I set up [a gist] to show a full setup with OMT.
|
|
18
|
-
|
|
19
|
-
### Config
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
// rollup.config.js
|
|
23
|
-
import OMT from "@trickfilm400/rollup-plugin-off-main-thread";
|
|
24
|
-
|
|
25
|
-
export default {
|
|
26
|
-
input: ["src/main.js"],
|
|
27
|
-
output: {
|
|
28
|
-
dir: "dist",
|
|
29
|
-
// You _must_ use either “amd” or “esm” as your format.
|
|
30
|
-
// But note that only very few browsers have native support for
|
|
31
|
-
// modules in workers.
|
|
32
|
-
format: "amd"
|
|
33
|
-
},
|
|
34
|
-
plugins: [OMT()]
|
|
35
|
-
};
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### Auto bundling
|
|
39
|
-
|
|
40
|
-
In your project's code use a module-relative path via `new URL` to include a Worker:
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
const worker = new Worker(new URL("worker.js", import.meta.url), {
|
|
44
|
-
type: "module"
|
|
45
|
-
});
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
This will just work.
|
|
49
|
-
|
|
50
|
-
If required, the plugin also supports plain literal paths:
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
const worker = new Worker("./worker.js", { type: "module" });
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
However, those are less portable: in Rollup they would result in module-relative
|
|
57
|
-
path, but if used directly in the browser, they'll be relative to the document
|
|
58
|
-
URL instead.
|
|
59
|
-
|
|
60
|
-
Hence, they're deprecated and `new URL` pattern is encouraged instead for portability.
|
|
61
|
-
|
|
62
|
-
### Importing workers as URLs
|
|
63
|
-
|
|
64
|
-
If your worker constructor doesn't match `workerRegexp` (see options below), you might find it easier to import the worker as a URL. In your project's code:
|
|
65
|
-
|
|
66
|
-
```js
|
|
67
|
-
import workerURL from "omt:./worker.js";
|
|
68
|
-
import paintWorkletURL from "omt:./paint-worklet.js";
|
|
69
|
-
|
|
70
|
-
const worker = new Worker(workerURL, { name: "main-worker" });
|
|
71
|
-
CSS.paintWorklet.addModule(paintWorkletURL);
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
`./worker.js` and `./paint-worklet.js` will be added to the output as chunks.
|
|
75
|
-
|
|
76
|
-
## Options
|
|
77
|
-
|
|
78
|
-
```js
|
|
79
|
-
{
|
|
80
|
-
// ...
|
|
81
|
-
plugins: [OMT(options)];
|
|
82
|
-
}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
- `loader`: A string containing the EJS template for the amd loader. If `undefined`, OMT will use `loader.ejs`.
|
|
86
|
-
- `useEval`: Use `fetch()` + `eval()` to load dependencies instead of `<script>` tags and `importScripts()`. _This is not CSP compliant, but is required if you want to use dynamic imports in ServiceWorker_.
|
|
87
|
-
- `workerRegexp`: A RegExp to find `new Workers()` calls. The second capture group _must_ capture the provided file name without the quotes.
|
|
88
|
-
- `amdFunctionName`: Function name to use instead of AMD’s `define`.
|
|
89
|
-
- `prependLoader`: A function that determines whether the loader code should be prepended to a certain chunk. Should return true if the load is suppsoed to be prepended.
|
|
90
|
-
- `urlLoaderScheme`: Scheme to use when importing workers as URLs. If `undefined`, OMT will use `"omt"`.
|
|
91
|
-
|
|
92
|
-
[when workers]: https://dassur.ma/things/when-workers
|
|
93
|
-
[a gist]: https://gist.github.com/surma/a02db7b53eb3e7870bf539b906ff6ff6
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
License Apache-2.0
|
|
1
|
+
# rollup-plugin-off-main-thread
|
|
2
|
+
|
|
3
|
+
Use Rollup with workers and ES6 modules _today_.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
$ npm install --save @trickfilm400/rollup-plugin-off-main-thread
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Workers are JavaScript’s version of threads. [Workers are important to use][when workers] as the main thread is already overloaded, especially on slower or older devices.
|
|
10
|
+
|
|
11
|
+
This plugin takes care of shimming module support in workers and allows you to use `new Worker()`.
|
|
12
|
+
|
|
13
|
+
OMT is the result of merging loadz0r and workz0r.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
I set up [a gist] to show a full setup with OMT.
|
|
18
|
+
|
|
19
|
+
### Config
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// rollup.config.js
|
|
23
|
+
import OMT from "@trickfilm400/rollup-plugin-off-main-thread";
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
input: ["src/main.js"],
|
|
27
|
+
output: {
|
|
28
|
+
dir: "dist",
|
|
29
|
+
// You _must_ use either “amd” or “esm” as your format.
|
|
30
|
+
// But note that only very few browsers have native support for
|
|
31
|
+
// modules in workers.
|
|
32
|
+
format: "amd"
|
|
33
|
+
},
|
|
34
|
+
plugins: [OMT()]
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Auto bundling
|
|
39
|
+
|
|
40
|
+
In your project's code use a module-relative path via `new URL` to include a Worker:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
const worker = new Worker(new URL("worker.js", import.meta.url), {
|
|
44
|
+
type: "module"
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
This will just work.
|
|
49
|
+
|
|
50
|
+
If required, the plugin also supports plain literal paths:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
const worker = new Worker("./worker.js", { type: "module" });
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
However, those are less portable: in Rollup they would result in module-relative
|
|
57
|
+
path, but if used directly in the browser, they'll be relative to the document
|
|
58
|
+
URL instead.
|
|
59
|
+
|
|
60
|
+
Hence, they're deprecated and `new URL` pattern is encouraged instead for portability.
|
|
61
|
+
|
|
62
|
+
### Importing workers as URLs
|
|
63
|
+
|
|
64
|
+
If your worker constructor doesn't match `workerRegexp` (see options below), you might find it easier to import the worker as a URL. In your project's code:
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
import workerURL from "omt:./worker.js";
|
|
68
|
+
import paintWorkletURL from "omt:./paint-worklet.js";
|
|
69
|
+
|
|
70
|
+
const worker = new Worker(workerURL, { name: "main-worker" });
|
|
71
|
+
CSS.paintWorklet.addModule(paintWorkletURL);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`./worker.js` and `./paint-worklet.js` will be added to the output as chunks.
|
|
75
|
+
|
|
76
|
+
## Options
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
{
|
|
80
|
+
// ...
|
|
81
|
+
plugins: [OMT(options)];
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- `loader`: A string containing the EJS template for the amd loader. If `undefined`, OMT will use `loader.ejs`.
|
|
86
|
+
- `useEval`: Use `fetch()` + `eval()` to load dependencies instead of `<script>` tags and `importScripts()`. _This is not CSP compliant, but is required if you want to use dynamic imports in ServiceWorker_.
|
|
87
|
+
- `workerRegexp`: A RegExp to find `new Workers()` calls. The second capture group _must_ capture the provided file name without the quotes.
|
|
88
|
+
- `amdFunctionName`: Function name to use instead of AMD’s `define`.
|
|
89
|
+
- `prependLoader`: A function that determines whether the loader code should be prepended to a certain chunk. Should return true if the load is suppsoed to be prepended.
|
|
90
|
+
- `urlLoaderScheme`: Scheme to use when importing workers as URLs. If `undefined`, OMT will use `"omt"`.
|
|
91
|
+
|
|
92
|
+
[when workers]: https://dassur.ma/things/when-workers
|
|
93
|
+
[a gist]: https://gist.github.com/surma/a02db7b53eb3e7870bf539b906ff6ff6
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
License Apache-2.0
|