UNPKG

8.86 kBTypeScriptView Raw
1import { AsyncSeriesHook, SyncHook, SyncWaterfallHook } from "tapable";
2import { compilation, Compiler, loader, Plugin, Stats } from "webpack";
3
4declare class WebpackAssetsManifest extends Plugin {
5 constructor(options?: WebpackAssetsManifest.Options);
6
7 /** https://github.com/webdeveric/webpack-assets-manifest#hooks */
8 hooks: {
9 apply: SyncHook<WebpackAssetsManifest>;
10
11 /**
12 * The `SyncWaterfallHook` class supports 3 type parameters only but this hook actually has 4 parameters.
13 * The type of 4th parameter is `compilation.Asset | null` with integrity added to info field.
14 *
15 * Refer to https://github.com/webdeveric/webpack-assets-manifest#hooks for details
16 */
17 customize: SyncWaterfallHook<WebpackAssetsManifest.Entry, WebpackAssetsManifest.Entry, WebpackAssetsManifest>;
18
19 transform: SyncWaterfallHook<WebpackAssetsManifest.Assets, WebpackAssetsManifest>;
20
21 done: AsyncSeriesHook<WebpackAssetsManifest, Stats>;
22
23 options: SyncWaterfallHook<WebpackAssetsManifest.Options>;
24
25 afterOptions: SyncHook<WebpackAssetsManifest.Options>;
26 };
27
28 /** https://github.com/webdeveric/webpack-assets-manifest#options-read-the-schema */
29 options: WebpackAssetsManifest.Options;
30
31 /** This is what gets JSON stringified */
32 assets: WebpackAssetsManifest.Assets;
33
34 /** original filename : hashed filename */
35 assetNames: Map<string, string>;
36
37 /** This is passed to the customize() hook */
38 currentAsset: compilation.Asset | null;
39
40 /** The Webpack compiler instance */
41 compiler: Compiler | null;
42
43 /** https://github.com/webdeveric/webpack-assets-manifest#options-read-the-schema */
44 get defaultOptions(): WebpackAssetsManifest.Options;
45
46 /** Determine if the manifest data is currently being merged */
47 get isMerging(): boolean;
48
49 /** Get the file extension */
50 getExtension(filename: string): string;
51
52 /** Replace backslash with forward slash */
53 fixKey(key: string): string;
54
55 /** Add item to assets without modifying the key or value */
56 setRaw(key: string, value: unknown): this;
57
58 /** Add an item to the manifest */
59 set(key: string, value: unknown): this;
60
61 /** Determine if an item exist in the manifest */
62 has(key: string): boolean;
63
64 /** Get an item from the manifest */
65 get(key: string, defaultValue?: unknown): unknown;
66
67 /** Delete an item from the manifest */
68 delete(key: string): boolean;
69
70 /** Process compilation assets */
71 processAssetsByChunkName(
72 assets: Record<string, string | ReadonlyArray<string>>,
73 hmrFiles?: Set<string>,
74 ): this["assetNames"];
75
76 /** Get the data for `JSON.stringify()` */
77 toJSON(): unknown;
78
79 /** `JSON.stringify()` the manifest */
80 toString(): string;
81
82 /** Merge data if the output file already exists */
83 maybeMerge(): void;
84
85 /** Emit the assets manifest */
86 emitAssetsManifest(compilation: compilation.Compilation): Promise<void>;
87
88 /** Get assets and hot module replacement files from a compilation object */
89 getCompilationAssets(compilation: compilation.Compilation): { assets: compilation.Asset[]; hmrFiles: Set<string> };
90
91 /** Handle the `emit` event */
92 handleEmit(compilation: compilation.Compilation): Promise<void>;
93
94 /** Get the parsed output path. [hash] is supported. */
95 getManifestPath(compilation: compilation.Compilation, filename: string): string;
96
97 /** Write the asset manifest to the file system */
98 writeTo(destination: string): Promise<void>;
99
100 clear(): void;
101
102 /** Cleanup before running Webpack */
103 handleWatchRun(): void;
104
105 /** Determine if the manifest should be written to disk with fs */
106 shouldWriteToDisk(compilation: compilation.Compilation): boolean;
107
108 /** Last chance to write the manifest to disk */
109 handleAfterEmit(compilation: compilation.Compilation): Promise<void>;
110
111 /** Record asset names */
112 handleNormalModuleLoader(
113 compilation: compilation.Compilation,
114 loaderContext: loader.LoaderContext,
115 module: compilation.Module,
116 ): void;
117
118 /** Add the SRI hash to the assetsInfo map */
119 recordSubresourceIntegrity(compilation: compilation.Compilation): void;
120
121 /** Hook into the compilation object */
122 handleCompilation(compilation: compilation.Compilation): void;
123
124 /**
125 * Determine if webpack-dev-server is being used
126 *
127 * The WEBPACK_DEV_SERVER / WEBPACK_SERVE env vars cannot be relied upon.
128 * See issue {@link https://github.com/webdeveric/webpack-assets-manifest/issues/125|#125}
129 */
130 inDevServer(): boolean;
131
132 /** Get the file system path to the manifest */
133 getOutputPath(): string;
134
135 /** Get the public path for the filename */
136 getPublicPath(filename: string): string;
137
138 /**
139 * Get a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler|Proxy} for the manifest.
140 * This allows you to use `[]` to manage entries.
141 *
142 * @param raw - Should the proxy use `setRaw` instead of `set`?
143 */
144 getProxy(raw?: boolean): WebpackAssetsManifest.Assets;
145}
146
147declare namespace WebpackAssetsManifest {
148 interface Options {
149 /** https://github.com/webdeveric/webpack-assets-manifest#enabled */
150 enabled?: boolean | undefined;
151
152 /** https://github.com/webdeveric/webpack-assets-manifest#assets */
153 assets?: Assets | undefined;
154
155 /** https://github.com/webdeveric/webpack-assets-manifest#output */
156 output?: string | undefined;
157
158 /** https://github.com/webdeveric/webpack-assets-manifest#replacer */
159 replacer?:
160 | ((this: unknown, key: string, value: unknown) => unknown)
161 | ReadonlyArray<string | number>
162 | null
163 | undefined;
164
165 /** https://github.com/webdeveric/webpack-assets-manifest#space */
166 space?: number | string | undefined;
167
168 /** https://github.com/webdeveric/webpack-assets-manifest#writetodisk */
169 writeToDisk?: boolean | "auto" | undefined;
170
171 /** https://github.com/webdeveric/webpack-assets-manifest#fileextregex */
172 fileExtRegex?: RegExp | null | false | undefined;
173
174 /** https://github.com/webdeveric/webpack-assets-manifest#sortmanifest */
175 sortManifest?: boolean | ((this: WebpackAssetsManifest, a: string, b: string) => number) | undefined;
176
177 /** https://github.com/webdeveric/webpack-assets-manifest#merge */
178 merge?: boolean | "customize" | undefined;
179
180 /** https://github.com/webdeveric/webpack-assets-manifest#publicpath */
181 publicPath?:
182 | string
183 | boolean
184 | null
185 | ((filename: string, manifest: WebpackAssetsManifest) => string)
186 | undefined;
187
188 /** https://github.com/webdeveric/webpack-assets-manifest#contextrelativekeys */
189 contextRelativeKeys?: boolean | undefined;
190
191 /** https://github.com/webdeveric/webpack-assets-manifest#apply */
192 apply?: ((manifest: WebpackAssetsManifest) => void) | null | undefined;
193
194 /** https://github.com/webdeveric/webpack-assets-manifest#customize */
195 customize?:
196 | ((
197 entry: Entry,
198 original: Entry,
199 manifest: WebpackAssetsManifest,
200 asset: (compilation.Asset & { info: Record<string, any> }) | null,
201 ) => Entry | false)
202 | null
203 | undefined;
204
205 /** https://github.com/webdeveric/webpack-assets-manifest#transform */
206 transform?: ((assets: Assets, manifest: WebpackAssetsManifest) => unknown) | null | undefined;
207
208 /** https://github.com/webdeveric/webpack-assets-manifest#done */
209 done?: ((manifest: WebpackAssetsManifest, stats: Stats) => void) | null | undefined;
210
211 /** https://github.com/webdeveric/webpack-assets-manifest#entrypoints */
212 entrypoints?: boolean | undefined;
213
214 /** https://github.com/webdeveric/webpack-assets-manifest#entrypointskey */
215 entrypointsKey?: string | false | undefined;
216
217 /** https://github.com/webdeveric/webpack-assets-manifest#entrypointsuseassets */
218 entrypointsUseAssets?: boolean | undefined;
219
220 /** https://github.com/webdeveric/webpack-assets-manifest#integrity */
221 integrity?: boolean | undefined;
222
223 /** https://github.com/webdeveric/webpack-assets-manifest#integrityhashes */
224 integrityHashes?: ReadonlyArray<string> | undefined;
225
226 /** https://github.com/webdeveric/webpack-assets-manifest#integritypropertyname */
227 integrityPropertyName?: string | undefined;
228 }
229
230 interface Entry {
231 key: string;
232 value: string;
233 }
234
235 interface Assets {
236 [key: string]: unknown;
237 }
238}
239
240export = WebpackAssetsManifest;
241
\No newline at end of file