old_contents: /* eslint-disable */
  export default class RequireEnsureHookPlugin {
  
    apply(compiler) {
      compiler.plugin('compilation', RequireEnsureHookPlugin.onCompilation);
    }
  
    static onCompilation(compilation) {
      const mainTemplate = compilation.mainTemplate;
  
      // add hook methods
      mainTemplate.plugin('require-extensions', function (source) {
        return this.asString([
          source,
          '',
          '// RequireEnsureHookPlugin',
          `${this.requireFn}.rjs = {`,
          this.indent([
            'hooks: [],',
            `hook: function (cb) { ${this.requireFn}.rjs.hooks.push(cb) },`,
            'unhook: function (cb) {',
            this.indent([
              `var hooks = ${this.requireFn}.rjs.hooks;`,
              'var i = hooks.indexOf(cb);',
              'if (i !== -1) { hooks.splice(i, 1); }',
            ]),
            '}',
          ]),
          '}',
        ]);
      });
  
      // add hook inside __webpack_require.e
      mainTemplate.plugin('require-ensure', function (currentSource) {
        return this.asString([
          '// RequireEnsureHookPlugin',
          `for (var i = 0; i < ${this.requireFn}.rjs.hooks.length; i++) {`,
          this.indent(`${this.requireFn}.rjs.hooks[i].apply(null, arguments);`),
          '}',
          '',
          currentSource,
        ]);
      });
    }
  }
  
new_contents: import Template from 'webpack/lib/Template';
  
  /**
   * This plugin hooks the require-ensure code generated by webpack
   * to let the pre-rendering server know which bundles have been used (and thus should be sent with the response).
   */
  export default class RequireEnsureHookPlugin {
  
    apply(compiler) {
      compiler.plugin('compilation', RequireEnsureHookPlugin.onCompilation);
    }
  
    static onCompilation(compilation) {
      const mainTemplate = compilation.mainTemplate;
  
      // add hook methods
      mainTemplate.hooks.requireExtensions.tap('RequireEnsureHookPlugin', currentSource => {
        return Template.asString([
          currentSource,
          '',
          '// RequireEnsureHookPlugin',
          `${mainTemplate.requireFn}.rjs = {`,
          Template.indent([
            'hooks: [],',
            `hook: function (cb) { ${mainTemplate.requireFn}.rjs.hooks.push(cb) },`,
            'unhook: function (cb) {',
            Template.indent([
              `var hooks = ${mainTemplate.requireFn}.rjs.hooks;`,
              'var i = hooks.indexOf(cb);',
              'if (i !== -1) { hooks.splice(i, 1); }',
            ]),
            '}',
          ]),
          '}',
        ]);
      });
  
      // add hook inside __webpack_require.e
      mainTemplate.hooks.requireEnsure.tap('require-ensure', currentSource => {
        return Template.asString([
          '// RequireEnsureHookPlugin',
          `for (var i = 0; i < ${mainTemplate.requireFn}.rjs.hooks.length; i++) {`,
          Template.indent(`${mainTemplate.requireFn}.rjs.hooks[i].apply(null, arguments);`),
          '}',
          '',
          currentSource,
        ]);
      });
    }
  }
  
subject: Update RequireEnsureHookPlugin