UNPKG

2.49 kBTypeScriptView Raw
1import Webpack, { Stats } from 'webpack';
2
3type ReporterContextFunc<T = any> = (context: WebpackBarPlugin, opts: T) => void
4
5interface State {
6 start: [number, number] | null
7 progress: number
8 done: boolean
9 message: string
10 details: string[]
11 request: null | {
12 file: null | string
13 loaders: string[]
14 }
15 hasErrors: boolean
16 color: string
17 name: string
18}
19
20interface Reporter {
21 /**
22 * Called when (re)compile is started
23 */
24 start?: ReporterContextFunc
25
26 /**
27 * Called when a file changed on watch mode
28 */
29 change?: ReporterContextFunc<{ shortPath: string }>
30
31 /**
32 * Called after each progress update
33 */
34 update?: ReporterContextFunc
35
36 /**
37 * Called when compile finished
38 */
39 done?: ReporterContextFunc<{ stats: Stats }>
40
41 /**
42 * Called when build progress updated
43 */
44 progress?: ReporterContextFunc
45
46 /**
47 * Called when _all_ compiles finished
48 */
49 allDone?: ReporterContextFunc
50
51 beforeAllDone?: ReporterContextFunc
52
53 afterAllDone?: ReporterContextFunc
54}
55
56type ReporterOpts = { reporter: Reporter | string, options?: any }
57type ReporterInput = string | [Reporter | string, any?] | ReporterOpts
58
59interface WebpackBarOptions {
60 /**
61 * Display name
62 * @default 'webpack'
63 */
64 name?: string
65
66 /**
67 * Color output of the progress bar
68 * @default 'green'
69 */
70 color?: string
71
72 /**
73 * Enable profiler
74 * @default false
75 */
76 profile?: boolean
77
78 /**
79 * Enable bars reporter
80 * Defaults to 'true' when not in CI or testing mod
81 * @default true
82 */
83 fancy?: boolean
84
85 /**
86 * Enable a simple log reporter (only start and end)
87 * Defaults to 'true' when running in minimal environments
88 * @default true
89 */
90 basic?: boolean
91
92 /**
93 * Register a custom reporter
94 */
95 reporter?: ReporterInput
96
97 /**
98 * Register an Array of your custom reporters.
99 * @default ['basic'] | ['fancy']
100 */
101 reporters?: ReporterInput[]
102}
103
104declare class WebpackBarPlugin extends Webpack.ProgressPlugin {
105 private options;
106 private reporters;
107 constructor(options?: WebpackBarOptions);
108 callReporters(fn: any, payload?: {}): void;
109 get hasRunning(): boolean;
110 get hasErrors(): boolean;
111 get statesArray(): any[];
112 get states(): {
113 [key: string]: State;
114 };
115 get state(): State;
116 _ensureState(): void;
117 apply(compiler: any): void;
118 updateProgress(percent?: number, message?: string, details?: any[]): void;
119}
120
121export { Reporter, State, WebpackBarPlugin as default };