Home > @lynx-js/template-webpack-plugin > TemplateHooks
#TemplateHooks interface
To allow other plugins to alter the Template, this plugin executes tapable hooks.
Signature:
export interface TemplateHooks #Example
class MyPlugin {
apply(compiler) {
compiler.hooks.compilation.tap("MyPlugin", (compilation) => {
console.log("The compiler is starting a new compilation...");
LynxTemplatePlugin.getLynxTemplatePluginHooks(compilation).beforeEmit.tapAsync(
"MyPlugin", // <-- Set a meaningful name here for stacktraces
(data, cb) => {
// Manipulate the content
modifyTemplate(data.template)
// Tell webpack to move on
cb(null, data);
},
);
});
}
}#Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
| afterEmit | AsyncSeriesWaterfallHook<{ outputName: string; }> | (ALPHA) Called after the template is emitted. | |
| asyncChunkName | SyncWaterfallHook<string> | (ALPHA) Get the real name of an async chunk. The files with the same asyncChunkName will be placed in the same template. | |
| beforeEmit | AsyncSeriesWaterfallHook<{ finalEncodeOptions: EncodeOptions; debugInfo: string; template: Buffer; outputName: string; mainThreadAssets: Asset[]; cssChunks: Asset[]; entryNames: string[]; }> | (ALPHA) Called before the template is emitted. Can be used to modify the template. | |
| beforeEncode | AsyncSeriesWaterfallHook<{ encodeData: EncodeRawData; filenameTemplate: string; entryNames: string[]; }> | (ALPHA) Called before the encode process. Can be used to modify the encode options. | |
| encode | AsyncSeriesBailHook<{ encodeOptions: EncodeOptions; intermediate?: string; }, { buffer: Buffer; debugInfo: string; }> | (ALPHA) Call the encode process. |

