Compiler Hooks
Compiler 모ëì CLI ëë Node API를 íµí´ ì ë¬ë 모ë ìµì
ì¼ë¡ ì»´íì¼ ì¸ì¤í´ì¤ë¥¼ ìì±íë ë©ì¸ ìì§ì
ëë¤.
íë¬ê·¸ì¸ ë±ë¡ ë° í¸ì¶ì ìí´ Tapableí´ëì¤ë¥¼ íì¥í©ëë¤.
ëë¶ë¶ì ì¬ì©ìì© íë¬ê·¸ì¸ì 먼ì Compilerì ë±ë¡ë©ëë¤.
Webpack íë¬ê·¸ì¸ì ê°ë°í ë, í
ì´ ì´ëì í¸ì¶ëëì§ ìê³ ì¶ì ì ììµëë¤. ì´ë¥¼ ìì ë³´ë ¤ë©´ webpack ìì¤ì½ëìì hooks.<hook name>.callì ê²ìí´ë³´ì¸ì.
Watching
Compilerë íì¼ ìì¤í
ì 모ëí°ë§íê³ íì¼ì´ ë³ê²½ëë©´ ë¤ì ì»´íì¼íë watchingì ì§ìí©ëë¤.
watch 모ëìì ì»´íì¼ë¬ë watchRun, watchClose ë° invalidì ê°ì ì¶ê° ì´ë²¤í¸ë¥¼ ë´ë³´ë
ëë¤.
ì´ê²ì ì¼ë°ì ì¼ë¡ developmentìì ì¬ì©ëë©° webpack-dev-serverì ê°ì ë구ì ë´ë¶ìì ì¬ì©ëì´ ê°ë°ìê° ë§¤ë² ìëì¼ë¡ ë¤ì ì»´íì¼í íì ìê² ëìì¤ëë¤.
watch 모ëë CLI를 íµí´ìë ìì í ì ììµëë¤.
Hooks
ìëìì ìê°í ë¼ì´í ì¬ì´í´ í
ë¤ì compilerì ìí´ ë
¸ì¶ë©ëë¤.
ìëì ê°ì´ ì ê·¼ í ì ììµëë¤.
compiler.hooks.someHook.tap("MyPlugin", (params) => {
/* ... */
});í
íì
ì ë°ë¼ì tapAsyncì tapPromise를 ì¬ì©í ì ììµëë¤.
í íì ì ëí ì¤ëª ì Tapable 문ì를 ì°¸ê³ íì¸ì.
environment
SyncHook
ì¤ì íì¼ìì íë¬ê·¸ì¸ì ì´ê¸°íí ì§í, ì»´íì¼ë¬ íê²½ì ì¤ë¹íë ëì í¸ì¶ë©ëë¤.
afterEnvironment
SyncHook
ì»´íì¼ë¬ íê²½ ì¤ì ì´ ìë£ë ëì¸ environment í
ë°ë¡ ë¤ì í¸ì¶ë©ëë¤.
entryOption
SyncBailHook
webpack ìµì
ì entry ì¤ì ì´ ì²ë¦¬ë í í¸ì¶ë©ëë¤.
compiler.hooks.entryOption.tap("MyPlugin", (context, entry) => {
/* ... */
});afterPlugins
SyncHook
ë´ë¶ íë¬ê·¸ì¸ì ì´ê¸° ì¤ì ì´ ìë£ë í í¸ì¶ë©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
compiler
afterResolvers
SyncHook
ë¦¬ì¡¸ë² ì¤ì ì´ ìë£ë í í¸ë¦¬ê±°ë©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
compiler
validate
SyncHook
Webpack ì¤ì , íë¬ê·¸ì¸ ë° ë¡ëì ëí ì í¨ì± ê²ì¬ ìì
ì ë±ë¡í기 ìí´ í¸ì¶ë©ëë¤. íë¬ê·¸ì¸ ê°ë°ìë ì´ í
ì íì©íì¬ compiler.validate(...)를 ì¬ì©íì¬ webpackì ë´ì¥ ì í¨ì± ê²ì¬ íë¦ì ì°¸ì¬í ì ììµëë¤.
compiler.hooks.validate.tap("MyPlugin", () => {
compiler.validate(
() => require("./schema/MyPlugin.json"),
options,
{ name: "My Plugin", baseDataPath: "options" },
(validatedOptions) => require("./schema/MyPlugin.check")(validatedOptions),
);
});initialize
SyncHook
ì»´íì¼ë¬ ê°ì²´ê° ì´ê¸°íë ë í¸ì¶ë©ëë¤.
beforeRun
AsyncSeriesHook
ì»´íì¼ë¬ë¥¼ ì¤íí기 ì§ì ì í ì ì¶ê°í©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
compiler
run
AsyncSeriesHook
ì»´íì¼ë¬ê° records를 ì½ê¸° ììí기 ì ì ì°ê²°í©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
compiler
watchRun
AsyncSeriesHook
ì ì»´íì¼ì´ í¸ë¦¬ê±°ë í ì»´íì¼ì´ ì¤ì ë¡ ììë기 ì ì watch 모ëìì íë¬ê·¸ì¸ì ì¤íí©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
compiler
normalModuleFactory
SyncHook
NormalModuleFactoryê° ìì±ë í í¸ì¶ë©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
normalModuleFactory
contextModuleFactory
SyncHook
ContextModuleFactoryê° ìì±ë í íë¬ê·¸ì¸ì ì¤íí©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
contextModuleFactory
beforeCompile
AsyncSeriesHook
ì»´íì¼ íë¼ë¯¸í°ê° ìì±ë í íë¬ê·¸ì¸ì ì¤íí©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
compilationParams
compilationParams ë³ìë ë¤ìê³¼ ê°ì´ ì´ê¸°íë©ëë¤.
compilationParams = {
normalModuleFactory,
contextModuleFactory,
};ì´ í ì ì»´íì¼ íë¼ë¯¸í°ë¥¼ ì¶ê° ëë ìì íë ë° ì¬ì©í ì ììµëë¤.
compiler.hooks.beforeCompile.tapAsync("MyPlugin", (params, callback) => {
params["MyPlugin - data"] = "important stuff my plugin will use later";
callback();
});compile
SyncHook
ì ì»´íì¼ì´ ìì±ë기 ì ì¸ beforeCompile ë°ë¡ ë¤ì í¸ì¶ë©ëë¤. ì´ í
ì ìì ì»´íì¼ë¬ì ë³µì¬ëì§ ììµëë¤.
- ì½ë°± íë¼ë¯¸í°:
compilationParams
thisCompilation
SyncHook
ì»´íì¼ì ì´ê¸°ííë ëì compilation ì´ë²¤í¸ë¥¼ ìì±í기 ì§ì ì ì¤íë©ëë¤. ì´ í
ì ìì ì»´íì¼ë¬ì ë³µì¬ëì§ ììµëë¤.
- ì½ë°± íë¼ë¯¸í°:
compilation,compilationParams
compilation
SyncHook
ì»´íì¼ì´ ìì±ë í íë¬ê·¸ì¸ì ì¤íí©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
compilation,compilationParams
make
AsyncParallelHook
ì»´íì¼ì ìë£í기 ì ì ì¤íë©ëë¤. ì´ í ì ìì ì»´íì¼ë¬ì ë³µì¬ëì§ ììµëë¤.
- ì½ë°± íë¼ë¯¸í°:
compilation
afterCompile
AsyncSeriesHook
ì»´íì¼ì ìë£íê³ ë´ì¸í í í¸ì¶ë©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
compilation
shouldEmit
SyncBailHook
ì ì ì ë°©ì¶í기 ì ì í¸ì¶ë©ëë¤. ë°©ì¶ ì¬ë¶ë¥¼ ìë ¤ì£¼ë booleanì ë°íí´ì¼ í©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
compilation
compiler.hooks.shouldEmit.tap(
"MyPlugin",
(compilation) =>
// ì¶ë ¥ì ë´ë³´ë´ë ¤ë©´ true를 ë°ííê³ , ê·¸ë ì§ ìì¼ë©´ false를 ë°íí©ëë¤.
true,
);emit
AsyncSeriesHook
ì ì ì ì¶ë ¥ ëë í°ë¦¬ë¡ ë°©ì¶í기 ì§ì ì ì¤íë©ëë¤. ì´ í ì ìì ì»´íì¼ë¬ì ë³µì¬ëì§ ììµëë¤.
- ì½ë°± íë¼ë¯¸í°:
compilation
afterEmit
AsyncSeriesHook
ì¶ë ¥ ëë í°ë¦¬ì ì ì ì ë´ë³´ë¸ í í¸ì¶ë©ëë¤. ì´ í ì ìì ì»´íì¼ë¬ì ë³µì¬ëì§ ììµëë¤.
- ì½ë°± íë¼ë¯¸í°:
compilation
assetEmitted
AsyncSeriesHook
ì ì ì´ ë°©ì¶ëìì ë ì¤íë©ëë¤. ì¶ë ¥ ê²½ë¡ ë° ë°ì´í¸ ì½í ì¸ ì ê°ì ë´ë³´ë¸ ì ì ì ì ë³´ì ëí ì ê·¼ì ì ê³µí©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
file,info
ì를 ë¤ì´ info.content를 íµí´ ì ì
ì ì½í
ì¸ ë²í¼ì ì ê·¼í ì ììµëë¤.
compiler.hooks.assetEmitted.tap(
"MyPlugin",
(file, { content, source, outputPath, compilation, targetPath }) => {
console.log(content); // <Buffer 66 6f 6f 62 61 72>
},
);done
AsyncSeriesHook
ì»´íì¼ì´ ìë£ëë©´ ì¤íë©ëë¤. ì´ í ì ìì ì»´íì¼ë¬ì ë³µì¬ëì§ ììµëë¤.
- ì½ë°± íë¼ë¯¸í°:
stats
additionalPass
AsyncSeriesHook
ì´ í ì ì¬ì©íë©´ ë¹ë를 í ë² ë ì¶ê°í ì ììµëë¤.
failed
SyncHook
ì»´íì¼ì´ ì¤í¨íë©´ í¸ì¶ë©ëë¤.
- ì½ë°± íë¼ë¯¸í°:
error
invalid
SyncHook
ê°ìì¤ì¸ ì»´íì¼ì´ 무í¨ê° ëìì ë ì¤íë©ëë¤. ì´ í ì ìì ì»´íì¼ë¬ì ë³µì¬ëì§ ììµëë¤.
- ì½ë°± íë¼ë¯¸í°:
fileName,changeTime
watchClose
SyncHook
ê°ìì¤ì¸ ì»´íì¼ì´ ì¤ì§ëìì ë í¸ì¶ë©ëë¤.
shutdown
AsyncSeriesHook
ì»´íì¼ë¬ê° ë«í ë í¸ì¶ë©ëë¤.
infrastructureLog
SyncBailHook
infrastructureLogging ìµì
ì íµí´ ì¤ì ìì íì±íë ê²½ì° ì¸íë¼ ë¡ê¹
ì ì¬ì©í ì ììµëë¤.
- ì½ë°± íë¼ë¯¸í°:
name,type,args
log
SyncBailHook
íì±íëë©´ statsì ë¡ê·¸ë¥¼ ìì±í ì ììµëë¤. stats.logging, stats.loggingDebug ë° stats.loggingTrace ìµì
ì ì°¸ê³ íì¸ì.
- ì½ë°± íë¼ë¯¸í°:
origin,logEntry



