Assetemitted
AsyncSeriesHook 在 asset 被输出时执行。此钩子可以访问被输出的 asset 的相关信息,例如它的输出路径和字节内容。 1. 回调参数:file, info 例如,可以通过 info.content访问 asset 的内容 buffer:
Beforecompile
AsyncSeriesHook 在创建 compilation parameter 之后执行。 1. 回调参数:compilationParams 初始化 compilationParams变量的示例如下: 此钩子可用于添加/修改 compilation parameter:
How do I tap a compiler hook?
They can be tapped the same way as compiler hooks:
compilation.hooks.someHook.tap(/* .. */); As with the compiler, tapAsync and tapPromise may also be available depending on the type of hook.
Triggered before a module build has started, can be used to modify the module.
Fired before rebuilding a module.
Run when a module build has failed. How do I use a compilation hook?
Here's an example of how to utilize the compilation.hooks.afterChunks hook.
Triggered at the beginning of the optimization phase.
Called at the beginning of the module optimization phase.
A plugin can tap into this hook to perform optimizations on modules.
Called after modules optimization has completed.
Infrastructurelog
SyncBailHook 在配置中启用 infrastructureLogging 选项后,允许使用 infrastructure log(基础日志)。 1. 回调参数:name, type, args
Thiscompilation
SyncHook 初始化 compilation 时调用,在触发 compilation 事件之前调用。这个钩子 不会被复制到子编译器。 1. 回调参数:compilation, compilationParams
What are compiler hooks?
Compiler Hooks The Compilermodule is the main engine that creates a compilation instancewith all the options passed through the CLIor Node API.
It extends theTapableclass in order to register and call plugins.
Most user-facing pluginsare first registered on the Compiler.
Why do we use tappromise method to tap into plugins?
When we use tapPromise method to tap into plugins, we need to return a promise which resolves when our asynchronous task is completed.
Once we can latch onto the webpack compiler and each individual compilations, the possibilities become endless for what we can do with the engine itself.