HotModuleReplacementPlugin

Enables Hot Module Replacement, otherwise known as HMR.

Basic Usage

Enabling HMR is straightforward; the plugin takes no options.

new webpack.HotModuleReplacementPlugin();

Hooks

updateManifest

5.113.0+

SyncHook<[manifest, { compilation, chunks, joinedSiblings }]>

Lets a plugin add its own data to the hot update manifest ([runtime].[fullhash].hot-update.json) that the runtime downloads, next to webpack's own c (updated chunks), r (removed chunks) and m (removed modules) fields:

import webpack from "webpack";

class MyHotDataPlugin {
  apply(compiler) {
    compiler.hooks.compilation.tap("MyHotDataPlugin", (compilation) => {
      webpack.HotModuleReplacementPlugin.getCompilationHooks(
        compilation,
      ).updateManifest.tap("MyHotDataPlugin", (manifest, { chunks }) => {
        manifest.myData = chunks.map((chunk) => chunk.id);
      });
    });
  }
}
Edit this page·

4 Contributors

skipjackbyzykchenxsansnitin315