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.getCompilationHooks(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

PropertyModifiersTypeDescription
afterEmitAsyncSeriesWaterfallHook<{ outputName: string; }>(ALPHA) Called after the template is emitted.
asyncChunkNameSyncWaterfallHook<string | undefined | null>(ALPHA) Get the real name of an async chunk. The files with the same asyncChunkName will be placed in the same template.
beforeEmitAsyncSeriesWaterfallHook<{ finalEncodeOptions: EncodeOptions; debugInfo: string; template: Buffer; outputName: string; mainThreadAssets: Asset[]; }>(ALPHA) Called before the template is emitted. Can be used to modify the template.
beforeEncodeAsyncSeriesWaterfallHook<{ encodeData: EncodeRawData; filenameTemplate: string; entryNames: string[]; }>(ALPHA) Called before the encode process. Can be used to modify the encode options.
encodeAsyncSeriesBailHook<{ encodeOptions: EncodeOptions; intermediate: string; }, { buffer: Buffer; debugInfo: string; }>(ALPHA) Call the encode process.