index.d.ts 2.4 KB

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