總之有這么多鉤子可以用:
- entryOption:在entry配置項處理前被調用,可以修改entry配置項;
- beforeRun:在運行編譯器前被調用;
- run:在開始讀取記錄時被調用;
- emit:生成資源到output目錄之前被調用;
- afterEmit:生成資源到output目錄之后被調用;
- thisCompilation:在compilation創建之前被調用,可以用于注冊額外的插件等;
- compilation:在compilation創建時被調用,用于注冊一些回調等;
- normalModuleFactory:在normal module工廠創建之后被調用,可以在模塊加載前完成一些準備工作;
- contextModuleFactory:類似于normalModuleFactory,但是用于動態上下文模塊;
- beforeCompile:編譯器開始編譯之前被調用;
- compile:編譯器開始編譯時被調用;
- afterCompile:編譯器完成編譯之后被調用;
- watchRun:在watch模式編譯器運行之前被調用;
- failed:當編譯失敗時被調用;
- done:同時編譯和重新編譯完成后被調用。
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例2.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}
案例1.entryOption
class MyEntryOptionPlugin {apply(compiler) {compiler.hooks.entryOption.tap("MyEntryOptionPlugin", (context, entry) => {// 遍歷所有入口配置for (const entryName in entry) {const entryPath = entry[entryName];// 處理入口路徑const newEntryPath = modifyEntryPath(entryPath);// 更新入口配置entry[entryName] = newEntryPath;}});}
}
function modifyEntryPath(path) {// 在路徑前添加前綴return `./src/${path}`;
}