Skip to content

Commit c2e4d84

Browse files
authored
🤖 Merge PR DefinitelyTyped#74600 [@types/worker-plugin]: update types by @arturovt
1 parent e99e3a5 commit c2e4d84

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

types/worker-plugin/index.d.ts

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,66 @@ import webpack = require("webpack");
22

33
export = WorkerPlugin;
44

5-
declare class WorkerPlugin extends webpack.Plugin {
5+
declare class WorkerPlugin implements webpack.WebpackPluginInstance {
66
constructor(options?: WorkerPlugin.Options);
7+
apply(compiler: webpack.Compiler): void;
78
}
89

910
declare namespace WorkerPlugin {
1011
interface Options {
12+
/**
13+
* Controls the name of the generated worker chunk.
14+
* The name is used to generate a URL according to `output.chunkFilename`.
15+
*/
1116
filename?: string | undefined;
17+
18+
/**
19+
* Controls the chunk filename of secondary chunks generated by the worker bundle.
20+
* Defaults to the parent compiler's `output.chunkFilename`.
21+
*/
1222
chunkFilename?: string | undefined;
23+
24+
/**
25+
* Configures the value of `output.globalObject` for WorkerPlugin's internal Webpack compiler.
26+
* Set to `false` to disable the warning when `output.globalObject` is set to `"window"`.
27+
* Defaults to `"self"`, which is required for HMR to work correctly in workers.
28+
*/
1329
globalObject?: false | string | undefined;
14-
plugins?: Array<string | webpack.Plugin> | undefined;
30+
1531
/**
16-
* If set to `true`, this option enables the bundling of [SharedWorker](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker)
32+
* List of Webpack plugins to apply to the worker's child compiler.
33+
* By default, no plugins from the parent compiler are applied to avoid running things
34+
* like `html-webpack-plugin` twice. Pass a plugin name string to copy it from the
35+
* parent compiler's configuration, or pass a plugin instance to apply it only to worker code.
36+
*/
37+
plugins?: Array<string | webpack.WebpackPluginInstance> | undefined;
38+
39+
/**
40+
* If set to `true`, enables bundling of
41+
* [`SharedWorker`](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker).
42+
* @default false
1743
*/
1844
sharedWorker?: boolean | undefined;
45+
1946
/**
20-
* If set to `false`, this option disables the bundling of [Worker].
21-
* Intended to be used with `{ sharedWorker: true }` to allow bundling of [SharedWorker] only without also bundling [Worker].
47+
* If set to `false`, disables bundling of `Worker`.
48+
* Intended to be used with `{ sharedWorker: true }` to bundle `SharedWorker` only.
49+
* @default true
2250
*/
2351
worker?: boolean | undefined;
52+
53+
/**
54+
* If set to `true`, retains `{ type: 'module' }` in the bundled output instead of
55+
* removing it. By default, WorkerPlugin removes the `type` option to compile
56+
* Module Workers to Classic Workers, which are supported in all browsers.
57+
* @default false
58+
*/
2459
preserveTypeModule?: boolean | undefined;
60+
2561
/**
26-
* Normally, WorkerPlugin will transform `new Worker('./a.js', { type: 'module' })`
27-
* to completely remove the `type` option, outputting something like `new Worker('a.worker.js')`.
28-
* This allows the plugin to compile Module Workers to Classic Workers, which are supported in all browsers.
62+
* Override the `type` value output by WorkerPlugin in the worker constructor options.
63+
* For example, setting `workerType: 'foo'` will output `new Worker('a.worker.js', { type: 'foo' })`.
64+
* Takes precedence over `preserveTypeModule`.
2965
*/
3066
workerType?: string | undefined;
3167
}

types/worker-plugin/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
"https://github.com/GoogleChromeLabs/worker-plugin"
77
],
88
"dependencies": {
9-
"@types/webpack": "^4"
9+
"@types/webpack": "^5"
1010
},
1111
"devDependencies": {
1212
"@types/worker-plugin": "workspace:."
1313
},
1414
"owners": [
1515
{
16-
"name": "Artur Androsovych",
16+
"name": "arturovt",
1717
"githubUsername": "arturovt"
1818
},
1919
{

types/worker-plugin/worker-plugin-tests.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ new WorkerPlugin({
1111
chunkFilename: "[id]_worker_chunk.js",
1212
});
1313

14-
class ExistingPlugin extends webpack.Plugin {}
14+
class ExistingPlugin implements webpack.WebpackPluginInstance {
15+
apply(compiler: webpack.Compiler): void {}
16+
}
1517

1618
const optionsArray: WorkerPlugin.Options[] = [
1719
{

0 commit comments

Comments
 (0)