-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.d.ts
146 lines (144 loc) · 5.18 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { Compiler } from 'webpack'
export interface BackgroundOptions {
/** Undocumented. */
noDynamicEntryWarning?: boolean
/**
* @deprecated
* Use pageEntry and/or serviceWorkerEntry instead.
*/
entry?: never
/** @deprecated */
manifest?: never
/**
* The entry point of the background page.
*/
pageEntry?: string
/**
* The entry point of the service worker.
*/
serviceWorkerEntry?: string
/**
* Only affects Manifest V3.
*
* Load all chunks at the beginning to workaround the Chrome bug
* <https://bugs.chromium.org/p/chromium/issues/detail?id=1198822>.
*
* NOT working for rspack.
*
* @defaultValue true
*/
eagerChunkLoading?: boolean
/**
* Add the support code that uses
* `chrome.scripting.executeScript` (MV3) or
* `chrome.tabs.executeScript` (MV2) when
* dynamic import does not work for chunk loading in the content script.
* @defaultValue true
*/
classicLoader?: boolean
/**
* Add a try-catch wrapper around the entry file of serviceWorkerEntry
* so if the initial code throws, you can still open the console of it.
*
* Does not work in rspack.
*
* @defaultValue true
*/
tryCatchWrapper?: boolean
}
export interface WebExtensionPluginOptions {
/** Background page/service worker options. */
background?: BackgroundOptions
/**
* Configure HMR automatically for you.
* @defaultValue true
*/
hmrConfig?: boolean
/**
*
* **This is an experimental API.**
* **API might change at any time.**
* **Please provide feedback!**
*
* This option helps the initial chunk loading of content scripts/the background service worker,
* usually needed when `optimization.runtimeChunk` or `optimization.splitChunks.chunks` is used.
*
* This option accepts an object, where the keys are the entry name,
* and the value is described below.
*
* This option replaces the HTMLWebpackPlugin where the background service worker and content scripts
* do not use HTML to load files.
*
* If the value is a `string` (an output file name), for content scripts, it creates an extra
* entry file to load all initial chunks **asynchronously** via dynamic import.
* This asynchronous loading behavior is limited to the platform limit and **breaks**
* [run_at](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts#run_at).
*
* If the value is a `string` (an output file name), for the background service worker (specified
* via `options.background.serviceWorkerEntry`), it creates an extra entry file to load all
* initial chunks **synchronously**.
*
* The file name specified MUST NOT be any existing file.
*
* If the value is a `function` (`(manifest: any, chunks: string[]) => void`), it requires
* a "manifest.json" in the emitted files and lets you edit it on the fly to include all
* the initial chunks. This option does not apply to the background service worker because
* `manifest.json` does not accept multiple files.
*
* If the value is an `object` (`{ file: string; touch(manifest: any, file: string): void }`),
* it generates a new file (see the behavior of `string` above) and provides a callback to
* edit the `manifest.json` (see the behavior of `function` above).
*
* If the value is `false`, it asserts that this entry does not have more than one initial file,
* otherwise, it will be a compile error.
*
* If the value is `undefined`, it silences the warning for the background service worker.
*
* You can also change your configuration to avoid `optimization.runtimeChunk` or `optimization.splitChunks.chunks`,
* in this case, webpack only generates 1 initial file so you don't need this option.
*
* @defaultValue undefined
* @example
* ```ts
* {
* // creates a entryName.js that dynamic import all the files needed.
* "contentScript1": "cs1.js",
* // edit the manifest.json directly to load all files synchronously.
* "contentScript2": (manifest, files) => {
* manifest.content_scripts[0].js = files;
* manifest.content_scripts[1].js = files;
* },
* "backgroundWorker": {
* file: "backgroundWorker.js",
* touch(manifest, file) {
* manifest.background.service_worker = file;
* }
* },
* }
* ```
*/
experimental_output?: Record<
string,
// throw error if the entry has more than one initial chunk.
| false
// generate a new file to load all all the initial chunks
// and provide a callback to set all initial files
| string
// provide a callback to set all initial files
| ((manifest: any, chunks: string[]) => void)
// generate a new file to load all the initial chunks
| { file: string; touch(manifest: any, file: string): void }
>
/**
* Use a weak runtime check, in case the code will be evaluated during the compile.
*
* Enable this option when you're using mini-css-extract-plugin.
* @defaultValue false
*/
weakRuntimeCheck?: boolean
}
export default class WebExtensionPlugin {
constructor(options?: WebExtensionPluginOptions)
apply(compiler: Compiler): void
}
export = WebExtensionPlugin