-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34f97a6
commit caa9206
Showing
5 changed files
with
77 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const PLUGIN_NAME = 'BuildTimeReporterWebpackPlugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import webpack from 'webpack'; | ||
import dashify from 'dashify'; | ||
import { PLUGIN_NAME } from './constants'; | ||
|
||
export function tapInto( | ||
context: webpack.Compiler | webpack.compilation.Compilation, | ||
hook: string, | ||
cb: (...args: any[]) => void, | ||
): void { | ||
if (context.hooks) { | ||
context.hooks[hook].tap(PLUGIN_NAME, cb); | ||
} else { | ||
(context as webpack.Compiler).plugin(dashify(hook), (...args) => { | ||
const callback = args.pop(); | ||
cb(...args, callback); | ||
if (callback && callback instanceof Function) { | ||
callback(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export function tapPromiseInto( | ||
compiler: webpack.Compiler, | ||
hook: string, | ||
cb: (compilation: webpack.compilation.Compilation) => Promise<void>, | ||
): void { | ||
if (compiler.hooks) { | ||
compiler.hooks[hook].tapPromise(PLUGIN_NAME, cb); | ||
} else { | ||
compiler.plugin(dashify(hook), (compilation, callback) => { | ||
cb(compilation).then(callback).catch(callback); | ||
}); | ||
} | ||
} | ||
|
||
export function getLogger(compiler: webpack.Compiler): webpack.Logger { | ||
return compiler.getInfrastructureLogger | ||
? compiler.getInfrastructureLogger(PLUGIN_NAME) | ||
: ((console as unknown) as webpack.Logger); | ||
} |