1
|
|
|
interface RollupError extends RollupLogProps { |
2
|
|
|
parserError?: Error; |
3
|
|
|
stack?: string; |
4
|
|
|
watchFiles?: string[]; |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
interface RollupWarning extends RollupLogProps { |
8
|
|
|
chunkName?: string; |
9
|
|
|
cycle?: string[]; |
10
|
|
|
exportName?: string; |
11
|
|
|
exporter?: string; |
12
|
|
|
guess?: string; |
13
|
|
|
importer?: string; |
14
|
|
|
missing?: string; |
15
|
|
|
modules?: string[]; |
16
|
|
|
names?: string[]; |
17
|
|
|
reexporter?: string; |
18
|
|
|
source?: string; |
19
|
|
|
sources?: string[]; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
interface RollupLogProps { |
23
|
|
|
code?: string; |
24
|
|
|
frame?: string; |
25
|
|
|
hook?: string; |
26
|
|
|
id?: string; |
27
|
|
|
loc?: { |
28
|
|
|
column: number; |
29
|
|
|
file?: string; |
30
|
|
|
line: number; |
31
|
|
|
}; |
32
|
|
|
message: string; |
33
|
|
|
name?: string; |
34
|
|
|
plugin?: string; |
35
|
|
|
pluginCode?: string; |
36
|
|
|
pos?: number; |
37
|
|
|
url?: string; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
type SourceMapSegment = |
41
|
|
|
| [number] |
42
|
|
|
| [number, number, number, number] |
43
|
|
|
| [number, number, number, number, number]; |
44
|
|
|
|
45
|
|
|
interface ExistingDecodedSourceMap { |
46
|
|
|
file?: string; |
47
|
|
|
mappings: SourceMapSegment[][]; |
48
|
|
|
names: string[]; |
49
|
|
|
sourceRoot?: string; |
50
|
|
|
sources: string[]; |
51
|
|
|
sourcesContent?: string[]; |
52
|
|
|
version: number; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
interface ExistingRawSourceMap { |
56
|
|
|
file?: string; |
57
|
|
|
mappings: string; |
58
|
|
|
names: string[]; |
59
|
|
|
sourceRoot?: string; |
60
|
|
|
sources: string[]; |
61
|
|
|
sourcesContent?: string[]; |
62
|
|
|
version: number; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
type DecodedSourceMapOrMissing = |
66
|
|
|
| { |
67
|
|
|
mappings?: never; |
68
|
|
|
missing: true; |
69
|
|
|
plugin: string; |
70
|
|
|
} |
71
|
|
|
| ExistingDecodedSourceMap; |
72
|
|
|
|
73
|
|
|
interface SourceMap { |
74
|
|
|
file: string; |
75
|
|
|
mappings: string; |
76
|
|
|
names: string[]; |
77
|
|
|
sources: string[]; |
78
|
|
|
sourcesContent: string[]; |
79
|
|
|
version: number; |
80
|
|
|
toString(): string; |
81
|
|
|
toUrl(): string; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
type SourceMapInput = ExistingRawSourceMap | string | null | { mappings: '' }; |
85
|
|
|
|
86
|
|
|
type PartialNull<T> = { |
87
|
|
|
[P in keyof T]: T[P] | null; |
88
|
|
|
}; |
89
|
|
|
|
90
|
|
|
interface ModuleOptions { |
91
|
|
|
meta: CustomPluginOptions; |
92
|
|
|
moduleSideEffects: boolean | 'no-treeshake'; |
93
|
|
|
syntheticNamedExports: boolean | string; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
interface SourceDescription extends Partial<PartialNull<ModuleOptions>> { |
97
|
|
|
ast?: AcornNode; |
98
|
|
|
code: string; |
99
|
|
|
map?: SourceMapInput; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
interface TransformModuleJSON extends Partial<PartialNull<ModuleOptions>> { |
103
|
|
|
ast?: AcornNode; |
104
|
|
|
code: string; |
105
|
|
|
// note if plugins use new this.cache to opt-out auto transform cache |
106
|
|
|
customTransformCache: boolean; |
107
|
|
|
originalCode: string; |
108
|
|
|
originalSourcemap: ExistingDecodedSourceMap | null; |
109
|
|
|
resolvedIds?: ResolvedIdMap; |
110
|
|
|
sourcemapChain: DecodedSourceMapOrMissing[]; |
111
|
|
|
transformDependencies: string[]; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
interface ModuleJSON extends TransformModuleJSON { |
115
|
|
|
ast: AcornNode; |
116
|
|
|
dependencies: string[]; |
117
|
|
|
id: string; |
118
|
|
|
transformFiles: EmittedFile[] | undefined; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
interface PluginCache { |
122
|
|
|
delete(id: string): boolean; |
123
|
|
|
get<T = any>(id: string): T; |
124
|
|
|
has(id: string): boolean; |
125
|
|
|
set<T = any>(id: string, value: T): void; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
interface MinimalPluginContext { |
129
|
|
|
meta: PluginContextMeta; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
interface EmittedAsset { |
133
|
|
|
fileName?: string; |
134
|
|
|
name?: string; |
135
|
|
|
source?: string | Uint8Array; |
136
|
|
|
type: 'asset'; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
interface EmittedChunk { |
140
|
|
|
fileName?: string; |
141
|
|
|
id: string; |
142
|
|
|
implicitlyLoadedAfterOneOf?: string[]; |
143
|
|
|
importer?: string; |
144
|
|
|
name?: string; |
145
|
|
|
preserveSignature?: PreserveEntrySignaturesOption; |
146
|
|
|
type: 'chunk'; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
type EmittedFile = EmittedAsset | EmittedChunk; |
150
|
|
|
|
151
|
|
|
type EmitAsset = (name: string, source?: string | Uint8Array) => string; |
152
|
|
|
|
153
|
|
|
type EmitChunk = (id: string, options?: { name?: string }) => string; |
154
|
|
|
|
155
|
|
|
type EmitFile = (emittedFile: EmittedFile) => string; |
156
|
|
|
|
157
|
|
|
interface ModuleInfo { |
158
|
|
|
ast: AcornNode | null; |
159
|
|
|
code: string | null; |
160
|
|
|
dynamicImporters: readonly string[]; |
161
|
|
|
dynamicallyImportedIds: readonly string[]; |
162
|
|
|
hasModuleSideEffects: boolean | 'no-treeshake'; |
163
|
|
|
id: string; |
164
|
|
|
implicitlyLoadedAfterOneOf: readonly string[]; |
165
|
|
|
implicitlyLoadedBefore: readonly string[]; |
166
|
|
|
importedIds: readonly string[]; |
167
|
|
|
importers: readonly string[]; |
168
|
|
|
isEntry: boolean; |
169
|
|
|
isExternal: boolean; |
170
|
|
|
meta: CustomPluginOptions; |
171
|
|
|
syntheticNamedExports: boolean | string; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
type GetModuleInfo = (moduleId: string) => ModuleInfo | null; |
175
|
|
|
|
176
|
|
|
interface CustomPluginOptions { |
177
|
|
|
[plugin: string]: any; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
interface PluginContext extends MinimalPluginContext { |
181
|
|
|
addWatchFile: (id: string) => void; |
182
|
|
|
cache: PluginCache; |
183
|
|
|
/** @deprecated Use `this.emitFile` instead */ |
184
|
|
|
emitAsset: EmitAsset; |
185
|
|
|
/** @deprecated Use `this.emitFile` instead */ |
186
|
|
|
emitChunk: EmitChunk; |
187
|
|
|
emitFile: EmitFile; |
188
|
|
|
error: (err: RollupError | string, pos?: number | { column: number; line: number }) => never; |
189
|
|
|
/** @deprecated Use `this.getFileName` instead */ |
190
|
|
|
getAssetFileName: (assetReferenceId: string) => string; |
191
|
|
|
/** @deprecated Use `this.getFileName` instead */ |
192
|
|
|
getChunkFileName: (chunkReferenceId: string) => string; |
193
|
|
|
getFileName: (fileReferenceId: string) => string; |
194
|
|
|
getModuleIds: () => IterableIterator<string>; |
195
|
|
|
getModuleInfo: GetModuleInfo; |
196
|
|
|
getWatchFiles: () => string[]; |
197
|
|
|
/** @deprecated Use `this.resolve` instead */ |
198
|
|
|
isExternal: IsExternal; |
199
|
|
|
/** @deprecated Use `this.getModuleIds` instead */ |
200
|
|
|
moduleIds: IterableIterator<string>; |
201
|
|
|
parse: (input: string, options?: any) => AcornNode; |
202
|
|
|
resolve: ( |
203
|
|
|
source: string, |
204
|
|
|
importer?: string, |
205
|
|
|
options?: { custom?: CustomPluginOptions; skipSelf?: boolean } |
206
|
|
|
) => Promise<ResolvedId | null>; |
207
|
|
|
/** @deprecated Use `this.resolve` instead */ |
208
|
|
|
resolveId: (source: string, importer?: string) => Promise<string | null>; |
209
|
|
|
setAssetSource: (assetReferenceId: string, source: string | Uint8Array) => void; |
210
|
|
|
warn: (warning: RollupWarning | string, pos?: number | { column: number; line: number }) => void; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
interface PluginContextMeta { |
214
|
|
|
rollupVersion: string; |
215
|
|
|
watchMode: boolean; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
interface ResolvedId extends ModuleOptions { |
219
|
|
|
external: boolean | 'absolute'; |
220
|
|
|
id: string; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
interface ResolvedIdMap { |
224
|
|
|
[key: string]: ResolvedId; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
interface PartialResolvedId extends Partial<PartialNull<ModuleOptions>> { |
228
|
|
|
external?: boolean | 'absolute' | 'relative'; |
229
|
|
|
id: string; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
type ResolveIdResult = string | false | null | undefined | PartialResolvedId; |
233
|
|
|
|
234
|
|
|
type ResolveIdHook = ( |
235
|
|
|
this: PluginContext, |
236
|
|
|
source: string, |
237
|
|
|
importer: string | undefined, |
238
|
|
|
options: { custom?: CustomPluginOptions } |
239
|
|
|
) => Promise<ResolveIdResult> | ResolveIdResult; |
240
|
|
|
|
241
|
|
|
type IsExternal = ( |
242
|
|
|
source: string, |
243
|
|
|
importer: string | undefined, |
244
|
|
|
isResolved: boolean |
245
|
|
|
) => boolean; |
246
|
|
|
|
247
|
|
|
type IsPureModule = (id: string) => boolean | null | undefined; |
248
|
|
|
|
249
|
|
|
type HasModuleSideEffects = (id: string, external: boolean) => boolean; |
250
|
|
|
|
251
|
|
|
type LoadResult = SourceDescription | string | null | undefined; |
252
|
|
|
|
253
|
|
|
type LoadHook = (this: PluginContext, id: string) => Promise<LoadResult> | LoadResult; |
254
|
|
|
|
255
|
|
|
interface TransformPluginContext extends PluginContext { |
256
|
|
|
getCombinedSourcemap: () => SourceMap; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
type TransformResult = string | null | undefined | Partial<SourceDescription>; |
260
|
|
|
|
261
|
|
|
type TransformHook = ( |
262
|
|
|
this: TransformPluginContext, |
263
|
|
|
code: string, |
264
|
|
|
id: string |
265
|
|
|
) => Promise<TransformResult> | TransformResult; |
266
|
|
|
|
267
|
|
|
type ModuleParsedHook = (this: PluginContext, info: ModuleInfo) => Promise<void> | void; |
268
|
|
|
|
269
|
|
|
type RenderChunkHook = ( |
270
|
|
|
this: PluginContext, |
271
|
|
|
code: string, |
272
|
|
|
chunk: RenderedChunk, |
273
|
|
|
options: NormalizedOutputOptions |
274
|
|
|
) => |
275
|
|
|
| Promise<{ code: string; map?: SourceMapInput } | null> |
276
|
|
|
| { code: string; map?: SourceMapInput } |
277
|
|
|
| string |
278
|
|
|
| null; |
279
|
|
|
|
280
|
|
|
type ResolveDynamicImportHook = ( |
281
|
|
|
this: PluginContext, |
282
|
|
|
specifier: string | AcornNode, |
283
|
|
|
importer: string |
284
|
|
|
) => Promise<ResolveIdResult> | ResolveIdResult; |
285
|
|
|
|
286
|
|
|
type ResolveImportMetaHook = ( |
287
|
|
|
this: PluginContext, |
288
|
|
|
prop: string | null, |
289
|
|
|
options: { chunkId: string; format: InternalModuleFormat; moduleId: string } |
290
|
|
|
) => string | null | undefined; |
291
|
|
|
|
292
|
|
|
type ResolveAssetUrlHook = ( |
293
|
|
|
this: PluginContext, |
294
|
|
|
options: { |
295
|
|
|
assetFileName: string; |
296
|
|
|
chunkId: string; |
297
|
|
|
format: InternalModuleFormat; |
298
|
|
|
moduleId: string; |
299
|
|
|
relativeAssetPath: string; |
300
|
|
|
} |
301
|
|
|
) => string | null | undefined; |
302
|
|
|
|
303
|
|
|
type ResolveFileUrlHook = ( |
304
|
|
|
this: PluginContext, |
305
|
|
|
options: { |
306
|
|
|
assetReferenceId: string | null; |
307
|
|
|
chunkId: string; |
308
|
|
|
chunkReferenceId: string | null; |
309
|
|
|
fileName: string; |
310
|
|
|
format: InternalModuleFormat; |
311
|
|
|
moduleId: string; |
312
|
|
|
referenceId: string; |
313
|
|
|
relativePath: string; |
314
|
|
|
} |
315
|
|
|
) => string | null | undefined; |
316
|
|
|
|
317
|
|
|
type AddonHookFunction = (this: PluginContext) => string | Promise<string>; |
318
|
|
|
type AddonHook = string | AddonHookFunction; |
319
|
|
|
|
320
|
|
|
type ChangeEvent = 'create' | 'update' | 'delete'; |
321
|
|
|
type WatchChangeHook = ( |
322
|
|
|
this: PluginContext, |
323
|
|
|
id: string, |
324
|
|
|
change: { event: ChangeEvent } |
325
|
|
|
) => void; |
326
|
|
|
|
327
|
|
|
interface OutputBundle { |
328
|
|
|
[fileName: string]: OutputAsset | OutputChunk; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
interface PluginHooks extends OutputPluginHooks { |
332
|
|
|
buildEnd: (this: PluginContext, err?: Error) => Promise<void> | void; |
333
|
|
|
buildStart: (this: PluginContext, options: NormalizedInputOptions) => Promise<void> | void; |
334
|
|
|
closeBundle: (this: PluginContext) => Promise<void> | void; |
335
|
|
|
closeWatcher: (this: PluginContext) => void; |
336
|
|
|
load: LoadHook; |
337
|
|
|
moduleParsed: ModuleParsedHook; |
338
|
|
|
options: ( |
339
|
|
|
this: MinimalPluginContext, |
340
|
|
|
options: InputOptions |
341
|
|
|
) => Promise<InputOptions | null | undefined> | InputOptions | null | undefined; |
342
|
|
|
resolveDynamicImport: ResolveDynamicImportHook; |
343
|
|
|
resolveId: ResolveIdHook; |
344
|
|
|
transform: TransformHook; |
345
|
|
|
watchChange: WatchChangeHook; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
interface OutputPluginHooks { |
349
|
|
|
augmentChunkHash: (this: PluginContext, chunk: PreRenderedChunk) => string | void; |
350
|
|
|
generateBundle: ( |
351
|
|
|
this: PluginContext, |
352
|
|
|
options: NormalizedOutputOptions, |
353
|
|
|
bundle: OutputBundle, |
354
|
|
|
isWrite: boolean |
355
|
|
|
) => void | Promise<void>; |
356
|
|
|
outputOptions: (this: PluginContext, options: OutputOptions) => OutputOptions | null | undefined; |
357
|
|
|
renderChunk: RenderChunkHook; |
358
|
|
|
renderDynamicImport: ( |
359
|
|
|
this: PluginContext, |
360
|
|
|
options: { |
361
|
|
|
customResolution: string | null; |
362
|
|
|
format: InternalModuleFormat; |
363
|
|
|
moduleId: string; |
364
|
|
|
targetModuleId: string | null; |
365
|
|
|
} |
366
|
|
|
) => { left: string; right: string } | null | undefined; |
367
|
|
|
renderError: (this: PluginContext, err?: Error) => Promise<void> | void; |
368
|
|
|
renderStart: ( |
369
|
|
|
this: PluginContext, |
370
|
|
|
outputOptions: NormalizedOutputOptions, |
371
|
|
|
inputOptions: NormalizedInputOptions |
372
|
|
|
) => Promise<void> | void; |
373
|
|
|
/** @deprecated Use `resolveFileUrl` instead */ |
374
|
|
|
resolveAssetUrl: ResolveAssetUrlHook; |
375
|
|
|
resolveFileUrl: ResolveFileUrlHook; |
376
|
|
|
resolveImportMeta: ResolveImportMetaHook; |
377
|
|
|
writeBundle: ( |
378
|
|
|
this: PluginContext, |
379
|
|
|
options: NormalizedOutputOptions, |
380
|
|
|
bundle: OutputBundle |
381
|
|
|
) => void | Promise<void>; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
interface OutputPluginValueHooks { |
385
|
|
|
banner: AddonHook; |
386
|
|
|
cacheKey: string; |
387
|
|
|
footer: AddonHook; |
388
|
|
|
intro: AddonHook; |
389
|
|
|
outro: AddonHook; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
interface Plugin extends Partial<PluginHooks>, Partial<OutputPluginValueHooks> { |
393
|
|
|
// for inter-plugin communication |
394
|
|
|
api?: any; |
395
|
|
|
name: string; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
interface OutputPlugin extends Partial<OutputPluginHooks>, Partial<OutputPluginValueHooks> { |
399
|
|
|
name: string; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
interface TreeshakingOptions { |
403
|
|
|
annotations?: boolean; |
404
|
|
|
moduleSideEffects?: ModuleSideEffectsOption; |
405
|
|
|
propertyReadSideEffects?: boolean | 'always'; |
406
|
|
|
/** @deprecated Use `moduleSideEffects` instead */ |
407
|
|
|
pureExternalModules?: PureModulesOption; |
408
|
|
|
tryCatchDeoptimization?: boolean; |
409
|
|
|
unknownGlobalSideEffects?: boolean; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
interface NormalizedTreeshakingOptions { |
413
|
|
|
annotations: boolean; |
414
|
|
|
moduleSideEffects: HasModuleSideEffects; |
415
|
|
|
propertyReadSideEffects: boolean | 'always'; |
416
|
|
|
tryCatchDeoptimization: boolean; |
417
|
|
|
unknownGlobalSideEffects: boolean; |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
interface GetManualChunkApi { |
421
|
|
|
getModuleIds: () => IterableIterator<string>; |
422
|
|
|
getModuleInfo: GetModuleInfo; |
423
|
|
|
} |
424
|
|
|
type GetManualChunk = (id: string, api: GetManualChunkApi) => string | null | undefined; |
425
|
|
|
|
426
|
|
|
type ExternalOption = |
427
|
|
|
| (string | RegExp)[] |
428
|
|
|
| string |
429
|
|
|
| RegExp |
430
|
|
|
| (( |
431
|
|
|
source: string, |
432
|
|
|
importer: string | undefined, |
433
|
|
|
isResolved: boolean |
434
|
|
|
) => boolean | null | undefined); |
435
|
|
|
type PureModulesOption = boolean | string[] | IsPureModule; |
436
|
|
|
type GlobalsOption = { [name: string]: string } | ((name: string) => string); |
437
|
|
|
type InputOption = string | string[] | { [entryAlias: string]: string }; |
438
|
|
|
type ManualChunksOption = { [chunkAlias: string]: string[] } | GetManualChunk; |
439
|
|
|
type ModuleSideEffectsOption = boolean | 'no-external' | string[] | HasModuleSideEffects; |
440
|
|
|
type PreserveEntrySignaturesOption = false | 'strict' | 'allow-extension' | 'exports-only'; |
441
|
|
|
type SourcemapPathTransformOption = ( |
442
|
|
|
relativeSourcePath: string, |
443
|
|
|
sourcemapPath: string |
444
|
|
|
) => string; |
445
|
|
|
|
446
|
|
|
interface InputOptions { |
447
|
|
|
acorn?: Record<string, unknown>; |
448
|
|
|
acornInjectPlugins?: (() => unknown)[] | (() => unknown); |
449
|
|
|
cache?: false | RollupCache; |
450
|
|
|
context?: string; |
451
|
|
|
experimentalCacheExpiry?: number; |
452
|
|
|
external?: ExternalOption; |
453
|
|
|
/** @deprecated Use the "inlineDynamicImports" output option instead. */ |
454
|
|
|
inlineDynamicImports?: boolean; |
455
|
|
|
input?: InputOption; |
456
|
|
|
makeAbsoluteExternalsRelative?: boolean | 'ifRelativeSource'; |
457
|
|
|
/** @deprecated Use the "manualChunks" output option instead. */ |
458
|
|
|
manualChunks?: ManualChunksOption; |
459
|
|
|
moduleContext?: ((id: string) => string | null | undefined) | { [id: string]: string }; |
460
|
|
|
onwarn?: WarningHandlerWithDefault; |
461
|
|
|
perf?: boolean; |
462
|
|
|
plugins?: Plugin[]; |
463
|
|
|
preserveEntrySignatures?: PreserveEntrySignaturesOption; |
464
|
|
|
/** @deprecated Use the "preserveModules" output option instead. */ |
465
|
|
|
preserveModules?: boolean; |
466
|
|
|
preserveSymlinks?: boolean; |
467
|
|
|
shimMissingExports?: boolean; |
468
|
|
|
strictDeprecations?: boolean; |
469
|
|
|
treeshake?: boolean | TreeshakingOptions; |
470
|
|
|
watch?: WatcherOptions | false; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
interface NormalizedInputOptions { |
474
|
|
|
acorn: Record<string, unknown>; |
475
|
|
|
acornInjectPlugins: (() => unknown)[]; |
476
|
|
|
cache: false | undefined | RollupCache; |
477
|
|
|
context: string; |
478
|
|
|
experimentalCacheExpiry: number; |
479
|
|
|
external: IsExternal; |
480
|
|
|
/** @deprecated Use the "inlineDynamicImports" output option instead. */ |
481
|
|
|
inlineDynamicImports: boolean | undefined; |
482
|
|
|
input: string[] | { [entryAlias: string]: string }; |
483
|
|
|
makeAbsoluteExternalsRelative: boolean | 'ifRelativeSource'; |
484
|
|
|
/** @deprecated Use the "manualChunks" output option instead. */ |
485
|
|
|
manualChunks: ManualChunksOption | undefined; |
486
|
|
|
moduleContext: (id: string) => string; |
487
|
|
|
onwarn: WarningHandler; |
488
|
|
|
perf: boolean; |
489
|
|
|
plugins: Plugin[]; |
490
|
|
|
preserveEntrySignatures: PreserveEntrySignaturesOption; |
491
|
|
|
/** @deprecated Use the "preserveModules" output option instead. */ |
492
|
|
|
preserveModules: boolean | undefined; |
493
|
|
|
preserveSymlinks: boolean; |
494
|
|
|
shimMissingExports: boolean; |
495
|
|
|
strictDeprecations: boolean; |
496
|
|
|
treeshake: false | NormalizedTreeshakingOptions; |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
type InternalModuleFormat = 'amd' | 'cjs' | 'es' | 'iife' | 'system' | 'umd'; |
500
|
|
|
|
501
|
|
|
type ModuleFormat = InternalModuleFormat | 'commonjs' | 'esm' | 'module' | 'systemjs'; |
502
|
|
|
|
503
|
|
|
type OptionsPaths = Record<string, string> | ((id: string) => string); |
504
|
|
|
|
505
|
|
|
type InteropType = boolean | 'auto' | 'esModule' | 'default' | 'defaultOnly'; |
506
|
|
|
|
507
|
|
|
type GetInterop = (id: string | null) => InteropType; |
508
|
|
|
|
509
|
|
|
type AmdOptions = ( |
510
|
|
|
| { |
511
|
|
|
autoId?: false; |
512
|
|
|
id: string; |
513
|
|
|
} |
514
|
|
|
| { |
515
|
|
|
autoId: true; |
516
|
|
|
basePath?: string; |
517
|
|
|
id?: undefined; |
518
|
|
|
} |
519
|
|
|
| { |
520
|
|
|
autoId?: false; |
521
|
|
|
id?: undefined; |
522
|
|
|
} |
523
|
|
|
) & { |
524
|
|
|
define?: string; |
525
|
|
|
}; |
526
|
|
|
|
527
|
|
|
type NormalizedAmdOptions = ( |
528
|
|
|
| { |
529
|
|
|
autoId: false; |
530
|
|
|
id?: string; |
531
|
|
|
} |
532
|
|
|
| { |
533
|
|
|
autoId: true; |
534
|
|
|
basePath: string; |
535
|
|
|
} |
536
|
|
|
) & { |
537
|
|
|
define: string; |
538
|
|
|
}; |
539
|
|
|
|
540
|
|
|
interface OutputOptions { |
541
|
|
|
amd?: AmdOptions; |
542
|
|
|
assetFileNames?: string | ((chunkInfo: PreRenderedAsset) => string); |
543
|
|
|
banner?: string | (() => string | Promise<string>); |
544
|
|
|
chunkFileNames?: string | ((chunkInfo: PreRenderedChunk) => string); |
545
|
|
|
compact?: boolean; |
546
|
|
|
// only required for bundle.write |
547
|
|
|
dir?: string; |
548
|
|
|
/** @deprecated Use the "renderDynamicImport" plugin hook instead. */ |
549
|
|
|
dynamicImportFunction?: string; |
550
|
|
|
entryFileNames?: string | ((chunkInfo: PreRenderedChunk) => string); |
551
|
|
|
esModule?: boolean; |
552
|
|
|
exports?: 'default' | 'named' | 'none' | 'auto'; |
553
|
|
|
extend?: boolean; |
554
|
|
|
externalLiveBindings?: boolean; |
555
|
|
|
// only required for bundle.write |
556
|
|
|
file?: string; |
557
|
|
|
footer?: string | (() => string | Promise<string>); |
558
|
|
|
format?: ModuleFormat; |
559
|
|
|
freeze?: boolean; |
560
|
|
|
globals?: GlobalsOption; |
561
|
|
|
hoistTransitiveImports?: boolean; |
562
|
|
|
indent?: string | boolean; |
563
|
|
|
inlineDynamicImports?: boolean; |
564
|
|
|
interop?: InteropType | GetInterop; |
565
|
|
|
intro?: string | (() => string | Promise<string>); |
566
|
|
|
manualChunks?: ManualChunksOption; |
567
|
|
|
minifyInternalExports?: boolean; |
568
|
|
|
name?: string; |
569
|
|
|
namespaceToStringTag?: boolean; |
570
|
|
|
noConflict?: boolean; |
571
|
|
|
outro?: string | (() => string | Promise<string>); |
572
|
|
|
paths?: OptionsPaths; |
573
|
|
|
plugins?: OutputPlugin[]; |
574
|
|
|
preferConst?: boolean; |
575
|
|
|
preserveModules?: boolean; |
576
|
|
|
preserveModulesRoot?: string; |
577
|
|
|
sanitizeFileName?: boolean | ((fileName: string) => string); |
578
|
|
|
sourcemap?: boolean | 'inline' | 'hidden'; |
579
|
|
|
sourcemapExcludeSources?: boolean; |
580
|
|
|
sourcemapFile?: string; |
581
|
|
|
sourcemapPathTransform?: SourcemapPathTransformOption; |
582
|
|
|
strict?: boolean; |
583
|
|
|
systemNullSetters?: boolean; |
584
|
|
|
validate?: boolean; |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
interface NormalizedOutputOptions { |
588
|
|
|
amd: NormalizedAmdOptions; |
589
|
|
|
assetFileNames: string | ((chunkInfo: PreRenderedAsset) => string); |
590
|
|
|
banner: () => string | Promise<string>; |
591
|
|
|
chunkFileNames: string | ((chunkInfo: PreRenderedChunk) => string); |
592
|
|
|
compact: boolean; |
593
|
|
|
dir: string | undefined; |
594
|
|
|
/** @deprecated Use the "renderDynamicImport" plugin hook instead. */ |
595
|
|
|
dynamicImportFunction: string | undefined; |
596
|
|
|
entryFileNames: string | ((chunkInfo: PreRenderedChunk) => string); |
597
|
|
|
esModule: boolean; |
598
|
|
|
exports: 'default' | 'named' | 'none' | 'auto'; |
599
|
|
|
extend: boolean; |
600
|
|
|
externalLiveBindings: boolean; |
601
|
|
|
file: string | undefined; |
602
|
|
|
footer: () => string | Promise<string>; |
603
|
|
|
format: InternalModuleFormat; |
604
|
|
|
freeze: boolean; |
605
|
|
|
globals: GlobalsOption; |
606
|
|
|
hoistTransitiveImports: boolean; |
607
|
|
|
indent: true | string; |
608
|
|
|
inlineDynamicImports: boolean; |
609
|
|
|
interop: GetInterop; |
610
|
|
|
intro: () => string | Promise<string>; |
611
|
|
|
manualChunks: ManualChunksOption; |
612
|
|
|
minifyInternalExports: boolean; |
613
|
|
|
name: string | undefined; |
614
|
|
|
namespaceToStringTag: boolean; |
615
|
|
|
noConflict: boolean; |
616
|
|
|
outro: () => string | Promise<string>; |
617
|
|
|
paths: OptionsPaths; |
618
|
|
|
plugins: OutputPlugin[]; |
619
|
|
|
preferConst: boolean; |
620
|
|
|
preserveModules: boolean; |
621
|
|
|
preserveModulesRoot: string | undefined; |
622
|
|
|
sanitizeFileName: (fileName: string) => string; |
623
|
|
|
sourcemap: boolean | 'inline' | 'hidden'; |
624
|
|
|
sourcemapExcludeSources: boolean; |
625
|
|
|
sourcemapFile: string | undefined; |
626
|
|
|
sourcemapPathTransform: SourcemapPathTransformOption | undefined; |
627
|
|
|
strict: boolean; |
628
|
|
|
systemNullSetters: boolean; |
629
|
|
|
validate: boolean; |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
type WarningHandlerWithDefault = ( |
633
|
|
|
warning: RollupWarning, |
634
|
|
|
defaultHandler: WarningHandler |
635
|
|
|
) => void; |
636
|
|
|
type WarningHandler = (warning: RollupWarning) => void; |
637
|
|
|
|
638
|
|
|
interface PreRenderedAsset { |
639
|
|
|
name: string | undefined; |
640
|
|
|
source: string | Uint8Array; |
641
|
|
|
type: 'asset'; |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
interface OutputAsset extends PreRenderedAsset { |
645
|
|
|
fileName: string; |
646
|
|
|
/** @deprecated Accessing "isAsset" on files in the bundle is deprecated, please use "type === \'asset\'" instead */ |
647
|
|
|
isAsset: true; |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
interface RenderedModule { |
651
|
|
|
code: string | null; |
652
|
|
|
originalLength: number; |
653
|
|
|
removedExports: string[]; |
654
|
|
|
renderedExports: string[]; |
655
|
|
|
renderedLength: number; |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
interface PreRenderedChunk { |
659
|
|
|
exports: string[]; |
660
|
|
|
facadeModuleId: string | null; |
661
|
|
|
isDynamicEntry: boolean; |
662
|
|
|
isEntry: boolean; |
663
|
|
|
isImplicitEntry: boolean; |
664
|
|
|
modules: { |
665
|
|
|
[id: string]: RenderedModule; |
666
|
|
|
}; |
667
|
|
|
name: string; |
668
|
|
|
type: 'chunk'; |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
interface RenderedChunk extends PreRenderedChunk { |
672
|
|
|
code?: string; |
673
|
|
|
dynamicImports: string[]; |
674
|
|
|
fileName: string; |
675
|
|
|
implicitlyLoadedBefore: string[]; |
676
|
|
|
importedBindings: { |
677
|
|
|
[imported: string]: string[]; |
678
|
|
|
}; |
679
|
|
|
imports: string[]; |
680
|
|
|
map?: SourceMap; |
681
|
|
|
referencedFiles: string[]; |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
interface OutputChunk extends RenderedChunk { |
685
|
|
|
code: string; |
686
|
|
|
} |
687
|
|
|
|
688
|
|
|
interface SerializablePluginCache { |
689
|
|
|
[key: string]: [number, any]; |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
interface RollupCache { |
693
|
|
|
modules: ModuleJSON[]; |
694
|
|
|
plugins?: Record<string, SerializablePluginCache>; |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
interface ChokidarOptions { |
698
|
|
|
alwaysStat?: boolean; |
699
|
|
|
atomic?: boolean | number; |
700
|
|
|
awaitWriteFinish?: |
701
|
|
|
| { |
702
|
|
|
pollInterval?: number; |
703
|
|
|
stabilityThreshold?: number; |
704
|
|
|
} |
705
|
|
|
| boolean; |
706
|
|
|
binaryInterval?: number; |
707
|
|
|
cwd?: string; |
708
|
|
|
depth?: number; |
709
|
|
|
disableGlobbing?: boolean; |
710
|
|
|
followSymlinks?: boolean; |
711
|
|
|
ignoreInitial?: boolean; |
712
|
|
|
ignorePermissionErrors?: boolean; |
713
|
|
|
ignored?: any; |
714
|
|
|
interval?: number; |
715
|
|
|
persistent?: boolean; |
716
|
|
|
useFsEvents?: boolean; |
717
|
|
|
usePolling?: boolean; |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
interface WatcherOptions { |
721
|
|
|
buildDelay?: number; |
722
|
|
|
chokidar?: ChokidarOptions; |
723
|
|
|
clearScreen?: boolean; |
724
|
|
|
exclude?: string | RegExp | (string | RegExp)[]; |
725
|
|
|
include?: string | RegExp | (string | RegExp)[]; |
726
|
|
|
skipWrite?: boolean; |
727
|
|
|
} |
728
|
|
|
|
729
|
|
|
interface AcornNode { |
730
|
|
|
end: number; |
731
|
|
|
start: number; |
732
|
|
|
type: string; |
733
|
|
|
} |
734
|
|
|
|
735
|
|
|
interface PenthouseConfig { |
736
|
|
|
/** Accessible url. Use file:/// protocol for local html files. */ |
737
|
|
|
url: string; |
738
|
|
|
/** Original css to extract critical css from */ |
739
|
|
|
cssString: string; |
740
|
|
|
/** Path to original css file on disk (if using instead of `cssString`) */ |
741
|
|
|
css: string; |
742
|
|
|
/** Width for critical viewport */ |
743
|
|
|
width: number; |
744
|
|
|
/** Height for critical viewport */ |
745
|
|
|
height: number; |
746
|
|
|
/** Configuration for screenshots (not used by default). See [Screenshot example](https://github.com/pocketjoso/penthouse/blob/master/examples/screenshots.js) */ |
747
|
|
|
screenshots: object; |
748
|
|
|
/** Keep media queries even for width/height values larger than critical viewport. */ |
749
|
|
|
keepLargerMediaQueries: boolean; |
750
|
|
|
/** |
751
|
|
|
* Array of css selectors to keep in critical css, even if not appearing in critical viewport. |
752
|
|
|
* Strings or regex (f.e. `['.keepMeEvenIfNotSeenInDom', /^\.button/]`) |
753
|
|
|
*/ |
754
|
|
|
forceInclude: Array<string>; |
755
|
|
|
/** |
756
|
|
|
* Array of css selectors to remove in critical css, even if appearing in critical viewport. |
757
|
|
|
* Strings or regex (f.e. `['.doNotKeepMeEvenIfNotSeenInDom', /^\.button/]`) |
758
|
|
|
*/ |
759
|
|
|
forceExclude: Array<string>; |
760
|
|
|
/** Css properties to filter out from critical css */ |
761
|
|
|
propertiesToRemove: Array<string>; |
762
|
|
|
/** Ms; abort critical CSS generation after this time */ |
763
|
|
|
timeout: number; |
764
|
|
|
/** Settings for puppeteer. See [Custom puppeteer browser example](https://github.com/pocketjoso/penthouse/blob/master/examples/custom-browser.js) */ |
765
|
|
|
puppeteer: object; |
766
|
|
|
/** Ms; stop waiting for page load after this time (for sites when page load event is unreliable) */ |
767
|
|
|
pageLoadSkipTimeout: number; |
768
|
|
|
/** |
769
|
|
|
* ms; wait time after page load before critical css extraction starts |
770
|
|
|
* (also before "before" screenshot is taken, if used) |
771
|
|
|
*/ |
772
|
|
|
renderWaitTime: number; |
773
|
|
|
/** set to false to load JS (not recommended) */ |
774
|
|
|
blockJSRequests: boolean; |
775
|
|
|
/** characters; strip out inline base64 encoded resources larger than this */ |
776
|
|
|
maxEmbeddedBase64Length: number; |
777
|
|
|
/** Can be specified to limit nr of elements to inspect per css selector, reducing execution time. */ |
778
|
|
|
maxElementsToCheckPerSelector: number; |
779
|
|
|
/** specify which user agent string when loading the page */ |
780
|
|
|
userAgent: string; |
781
|
|
|
/** Set extra http headers to be sent with the request for the url. */ |
782
|
|
|
customPageHeaders: object; |
783
|
|
|
/** For formatting of each cookie, see [Puppeteer setCookie docs](https://github.com/puppeteer/puppeteer/blob/v1.9.0/docs/api.md#pagesetcookiecookies) */ |
784
|
|
|
cookies: Array<string>; |
785
|
|
|
/** Make Penthouse throw on errors parsing the original CSS. Legacy option, not recommended */ |
786
|
|
|
strict: boolean; |
787
|
|
|
/** |
788
|
|
|
* Let Penthouse stop if the server response code is not matching this value. number and |
789
|
|
|
* regex types are tested against the [response.status()](https://github.com/puppeteer/puppeteer/blob/v1.14.0/docs/api.md#responsestatus). A function is also allowed and |
790
|
|
|
* gets [Response](https://github.com/puppeteer/puppeteer/blob/v1.14.0/docs/api.md#class-response) as argument. The function should return a boolean. |
791
|
|
|
*/ |
792
|
|
|
allowedResponseCode: number | RegExp | Function; |
793
|
|
|
} |
794
|
|
|
|
795
|
|
|
type DeclCallback = (node: object, value: string) => boolean; |
796
|
|
|
|
797
|
|
|
interface CriticalConfig { |
798
|
|
|
/** Inline critical-path CSS using filamentgroup's loadCSS. Pass an object to configure `inline-critical` */ |
799
|
|
|
inline: boolean; |
800
|
|
|
/** Base directory in which the source and destination are to be written */ |
801
|
|
|
base: string; |
802
|
|
|
/** HTML source to be operated against. This option takes precedence over the `src` option */ |
803
|
|
|
html: string; |
804
|
|
|
/** An array of paths to css files, file globs or Vinyl file objects. */ |
805
|
|
|
css: Array<string>; |
806
|
|
|
/** Location of the HTML source to be operated against */ |
807
|
|
|
src: string; |
808
|
|
|
/** |
809
|
|
|
* Location of where to save the output of an operation. |
810
|
|
|
* Use an object with 'html' and 'css' props if you want to store both |
811
|
|
|
*/ |
812
|
|
|
target: string | Partial<{ |
813
|
|
|
css: string; |
814
|
|
|
html: string; |
815
|
|
|
uncritical: string; |
816
|
|
|
}>; |
817
|
|
|
/** Width of the target viewport */ |
818
|
|
|
width: number; |
819
|
|
|
/** Height of the target viewport */ |
820
|
|
|
height: number; |
821
|
|
|
/** Enable minification of generated critical-path */ |
822
|
|
|
minify: boolean; |
823
|
|
|
/** |
824
|
|
|
* Remove the inlined styles from any stylesheets referenced in the HTML. |
825
|
|
|
* It generates new references based on extracted content so it's safe to use for |
826
|
|
|
* multiple HTML files referencing the same stylesheet. Use with caution. |
827
|
|
|
* Removing the critical CSS per page results in a unique async loaded CSS file for every page. |
828
|
|
|
* Meaning you can't rely on cache across multiple pages |
829
|
|
|
*/ |
830
|
|
|
extract: boolean; |
831
|
|
|
/** Inline images */ |
832
|
|
|
inlineImages: boolean; |
833
|
|
|
/** List of directories/urls where the inliner should start looking for assets */ |
834
|
|
|
assetPaths: Array<string>; |
835
|
|
|
/** Sets a max file size (in bytes) for base64 inlined images */ |
836
|
|
|
maxImageFileSize: number; |
837
|
|
|
/** |
838
|
|
|
* Critical tries it's best to rebase the asset paths relative to the document. |
839
|
|
|
* If this doesn't work as expected you can always use this option to control the rebase paths. |
840
|
|
|
* See postcss-url for details. (https://github.com/pocketjoso/penthouse#usage-1). |
841
|
|
|
*/ |
842
|
|
|
rebase: object | Function; |
843
|
|
|
/** ignore CSS rules */ |
844
|
|
|
ignore: Partial<{ |
845
|
|
|
atrule: Array<string>; |
846
|
|
|
rule: Array<string>; |
847
|
|
|
decl: DeclCallback; |
848
|
|
|
}>; |
849
|
|
|
/** User agent to use when fetching a remote src */ |
850
|
|
|
userAgent: string; |
851
|
|
|
/** Configuration options for `penthouse`. */ |
852
|
|
|
penthouse: Partial<PenthouseConfig>; |
853
|
|
|
/** Configuration options for `got`. */ |
854
|
|
|
request: object; |
855
|
|
|
/** RFC2617 basic authorization: `user` */ |
856
|
|
|
user: string; |
857
|
|
|
/** RFC2617 basic authorization: `pass` */ |
858
|
|
|
pass: string; |
859
|
|
|
/** Throw an error if no css is found */ |
860
|
|
|
strict: boolean; |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
interface CriticalPages { |
864
|
|
|
/** Combined with `criticalUrl` to determine the URLs to scrape for Critical CSS */ |
865
|
|
|
uri: string; |
866
|
|
|
/** Critical CSS files are named with the `template` path, and saved to the `criticalBase` directory */ |
867
|
|
|
template: string; |
868
|
|
|
} |
869
|
|
|
|
870
|
|
|
interface CriticalPluginConfig { |
871
|
|
|
/** |
872
|
|
|
* The base URL to use in combination with the `criticalPages` `uri`s to determine the URLs to scrape for Critical CSS. |
873
|
|
|
* This can also be a file system path. This is combined with `criticalPages.uri` |
874
|
|
|
* to determine pages to scrap for critical CSS. |
875
|
|
|
* Determines the `criticalConfig.src` property |
876
|
|
|
*/ |
877
|
|
|
criticalUrl: string; |
878
|
|
|
/** |
879
|
|
|
* The base file system path to where the generated Critical CSS file should be saved. |
880
|
|
|
* This is combined with `criticalPages.template` with `_critical.min.css` appended |
881
|
|
|
* to it to determine the saved critical CSS file name. |
882
|
|
|
* Determines the `criticalConfig.target` property |
883
|
|
|
*/ |
884
|
|
|
criticalBase?: string; |
885
|
|
|
/** |
886
|
|
|
* An array objects that contain the page `uri`s that are combined with the `criticalUrl` to |
887
|
|
|
* determine the URLs to scrape for Critical CSS. The resulting files are named with the |
888
|
|
|
* `template` path, and saved to the `criticalBase` directory |
889
|
|
|
*/ |
890
|
|
|
criticalPages: Partial<CriticalPages>[]; |
891
|
|
|
/** |
892
|
|
|
* This is the full [config for critical](https://github.com/addyosmani/critical#options) that is passed |
893
|
|
|
* through to the `critical` package. |
894
|
|
|
* You may optionally override any properties you like here |
895
|
|
|
*/ |
896
|
|
|
criticalConfig?: Partial<CriticalConfig>; |
897
|
|
|
} |
898
|
|
|
|
899
|
|
|
/** |
900
|
|
|
* [Vite.js](https://vitejs.dev/) & [Rollup](https://rollupjs.org/) plugin for generating critical CSS |
901
|
|
|
* that uses the [critical](https://github.com/addyosmani/critical) generator under the hood. |
902
|
|
|
* |
903
|
|
|
* @param {CriticalPluginConfig} pluginConfig - the plugin configuration object |
904
|
|
|
* @param {Function} callback - callback upon completion of the critical CSS generation |
905
|
|
|
* @constructor |
906
|
|
|
*/ |
907
|
|
|
declare function PluginCritical(pluginConfig: CriticalPluginConfig, callback?: Function): Plugin; |
908
|
|
|
|
909
|
|
|
export { CriticalPages, CriticalPluginConfig, PluginCritical }; |
910
|
|
|
|