JavascriptModulesPlugin

Handles the bundling of JavaScript, usually used to access the hooks of the JavascriptModulesPlugin:

class MyJsMinimizerPlugin {
  apply(compiler) {
    compiler.hooks.compilation.tap(MyJsMinimizerPlugin.name, compilation => {
      // Access the chunkHash hooks of JavascriptModulesPlugin
      const hooks =
        compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(
          compilation,
        );
      // Since the JS chunk has been optimized and its content has changed, the chunk hash for the JS chunk needs to be updated
      hooks.chunkHash.tap(MyJsMinimizerPlugin.name, (chunk, hash) => {
        hash.update(`minimized by ${MyJsMinimizerPlugin.name}`);
      });
      // Optimize the JS chunk
      compilation.hooks.processAssets.tap(MyJsMinimizerPlugin.name, assets => {
        optimize(assets);
      });
    });
  }
}