/* 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,
      ]);
    });
  }
}

@@ -1,21 +1,234 @@
-/* eslint-disable
+import Template from 'webpack/lib/Template';%0A%0A/**%0A * This plugin hooks the require-ensure code generated by webpack%0A * to let the pre-rendering server know which bundles have been used (and thus should be sent with the response).%0A
  */%0A
@@ -506,33 +506,30 @@
 emplate.
-plugin('
+hooks.
 require
--e
+E
 xtension
@@ -533,28 +533,56 @@
 ions
-', function (s
+.tap('RequireEnsureHookPlugin', currentS
 ource
-)
+ =%3E
  %7B%0A 
@@ -585,36 +585,40 @@
  %7B%0A      return 
-this
+Template
 .asString(%5B%0A    
@@ -621,17 +621,24 @@
         
-s
+currentS
 ource,%0A 
@@ -697,20 +697,28 @@
      %60$%7B
-this
+mainTemplate
 .require
@@ -731,36 +731,40 @@
 s = %7B%60,%0A        
-this
+Template
 .indent(%5B%0A      
@@ -816,20 +816,28 @@
 cb) %7B $%7B
-this
+mainTemplate
 .require
@@ -903,36 +903,40 @@
 ) %7B',%0A          
-this
+Template
 .indent(%5B%0A      
@@ -956,20 +956,28 @@
 oks = $%7B
-this
+mainTemplate
 .require
@@ -1221,22 +1221,39 @@
 emplate.
-plugin
+hooks.requireEnsure.tap
 ('requir
@@ -1263,26 +1263,16 @@
 nsure', 
-function (
 currentS
@@ -1276,17 +1276,19 @@
 ntSource
-)
+ =%3E
  %7B%0A     
@@ -1295,20 +1295,24 @@
  return 
-this
+Template
 .asStrin
@@ -1384,20 +1384,28 @@
 ; i %3C $%7B
-this
+mainTemplate
 .require
@@ -1443,20 +1443,24 @@
         
-this
+Template
 .indent(
@@ -1466,12 +1466,20 @@
 (%60$%7B
-this
+mainTemplate
 .req

Update RequireEnsureHookPlugin