@@ -8,6 +8,7 @@ const ConcatSource = require("webpack-sources").ConcatSource;
88const OriginalSource = require ( "webpack-sources" ) . OriginalSource ;
99const PrefixSource = require ( "webpack-sources" ) . PrefixSource ;
1010const Template = require ( "./Template" ) ;
11+ const Tapable = require ( "tapable" ) . Tapable ;
1112const SyncWaterfallHook = require ( "tapable" ) . SyncWaterfallHook ;
1213const SyncHook = require ( "tapable" ) . SyncHook ;
1314const SyncBailHook = require ( "tapable" ) . SyncBailHook ;
@@ -28,9 +29,10 @@ const SyncBailHook = require("tapable").SyncBailHook;
2829// __webpack_require__.oe = the uncatched error handler for the webpack runtime
2930// __webpack_require__.nc = the script nonce
3031
31- module . exports = class MainTemplate extends Template {
32+ module . exports = class MainTemplate extends Tapable {
3233 constructor ( outputOptions ) {
33- super ( outputOptions ) ;
34+ super ( ) ;
35+ this . outputOptions = outputOptions || { } ;
3436 this . hooks = {
3537 modules : new SyncWaterfallHook ( [ "modules" , "chunk" , "hash" , "moduleTemplate" , "dependencyTemplates" ] ) ,
3638 moduleObj : new SyncWaterfallHook ( [ "source" , "chunk" , "hash" , "moduleIdExpression" ] ) ,
@@ -61,7 +63,7 @@ module.exports = class MainTemplate extends Template {
6163 buf . push ( "// Load entry module and return exports" ) ;
6264 buf . push ( `return ${ this . renderRequireFunctionForModule ( hash , chunk , JSON . stringify ( chunk . entryModule . id ) ) } (${ this . requireFn } .s = ${ JSON . stringify ( chunk . entryModule . id ) } );` ) ;
6365 }
64- return this . asString ( buf ) ;
66+ return Template . asString ( buf ) ;
6567 } ) ;
6668 this . plugin ( "render" , ( bootstrapSource , chunk , hash , moduleTemplate , dependencyTemplates ) => {
6769 const source = new ConcatSource ( ) ;
@@ -70,40 +72,40 @@ module.exports = class MainTemplate extends Template {
7072 source . add ( "/******/ })\n" ) ;
7173 source . add ( "/************************************************************************/\n" ) ;
7274 source . add ( "/******/ (" ) ;
73- const modules = this . renderChunkModules ( chunk , ( ) => true , moduleTemplate , dependencyTemplates , "/******/ " ) ;
75+ const modules = Template . renderChunkModules ( chunk , ( ) => true , moduleTemplate , dependencyTemplates , "/******/ " ) ;
7476 source . add ( this . hooks . modules . call ( modules , chunk , hash , moduleTemplate , dependencyTemplates ) ) ;
7577 source . add ( ")" ) ;
7678 return source ;
7779 } ) ;
7880 this . plugin ( "local-vars" , ( source , chunk , hash ) => {
79- return this . asString ( [
81+ return Template . asString ( [
8082 source ,
8183 "// The module cache" ,
8284 "var installedModules = {};"
8385 ] ) ;
8486 } ) ;
8587 this . plugin ( "require" , ( source , chunk , hash ) => {
86- return this . asString ( [
88+ return Template . asString ( [
8789 source ,
8890 "// Check if module is in cache" ,
8991 "if(installedModules[moduleId]) {" ,
90- this . indent ( "return installedModules[moduleId].exports;" ) ,
92+ Template . indent ( "return installedModules[moduleId].exports;" ) ,
9193 "}" ,
9294 "// Create a new module (and put it into the cache)" ,
9395 "var module = installedModules[moduleId] = {" ,
94- this . indent ( this . hooks . moduleObj . call ( "" , chunk , hash , "moduleId" ) ) ,
96+ Template . indent ( this . hooks . moduleObj . call ( "" , chunk , hash , "moduleId" ) ) ,
9597 "};" ,
9698 "" ,
97- this . asString ( outputOptions . strictModuleExceptionHandling ? [
99+ Template . asString ( outputOptions . strictModuleExceptionHandling ? [
98100 "// Execute the module function" ,
99101 "var threw = true;" ,
100102 "try {" ,
101- this . indent ( [
103+ Template . indent ( [
102104 `modules[moduleId].call(module.exports, module, module.exports, ${ this . renderRequireFunctionForModule ( hash , chunk , "moduleId" ) } );` ,
103105 "threw = false;"
104106 ] ) ,
105107 "} finally {" ,
106- this . indent ( [
108+ Template . indent ( [
107109 "if(threw) delete installedModules[moduleId];"
108110 ] ) ,
109111 "}"
@@ -120,7 +122,7 @@ module.exports = class MainTemplate extends Template {
120122 ] ) ;
121123 } ) ;
122124 this . plugin ( "module-obj" , ( source , chunk , hash , varModuleId ) => {
123- return this . asString ( [
125+ return Template . asString ( [
124126 "i: moduleId," ,
125127 "l: false," ,
126128 "exports: {}"
@@ -132,9 +134,9 @@ module.exports = class MainTemplate extends Template {
132134 buf . push ( "// This file contains only the entry chunk." ) ;
133135 buf . push ( "// The chunk loading function for additional chunks" ) ;
134136 buf . push ( `${ this . requireFn } .e = function requireEnsure(chunkId) {` ) ;
135- buf . push ( this . indent ( "var promises = [];" ) ) ;
136- buf . push ( this . indent ( this . hooks . requireEnsure . call ( "" , chunk , hash , "chunkId" ) ) ) ;
137- buf . push ( this . indent ( "return Promise.all(promises);" ) ) ;
137+ buf . push ( Template . indent ( "var promises = [];" ) ) ;
138+ buf . push ( Template . indent ( this . hooks . requireEnsure . call ( "" , chunk , hash , "chunkId" ) ) ) ;
139+ buf . push ( Template . indent ( "return Promise.all(promises);" ) ) ;
138140 buf . push ( "};" ) ;
139141 }
140142 buf . push ( "" ) ;
@@ -148,11 +150,11 @@ module.exports = class MainTemplate extends Template {
148150 buf . push ( "" ) ;
149151 buf . push ( "// define getter function for harmony exports" ) ;
150152 buf . push ( `${ this . requireFn } .d = function(exports, name, getter) {` ) ;
151- buf . push ( this . indent ( [
153+ buf . push ( Template . indent ( [
152154 `if(!${ this . requireFn } .o(exports, name)) {` ,
153- this . indent ( [
155+ Template . indent ( [
154156 "Object.defineProperty(exports, name, {" ,
155- this . indent ( [
157+ Template . indent ( [
156158 "configurable: false," ,
157159 "enumerable: true," ,
158160 "get: getter"
@@ -166,17 +168,17 @@ module.exports = class MainTemplate extends Template {
166168 buf . push ( "" ) ;
167169 buf . push ( "// define __esModule on exports" ) ;
168170 buf . push ( `${ this . requireFn } .r = function(exports) {` ) ;
169- buf . push ( this . indent ( [
171+ buf . push ( Template . indent ( [
170172 "Object.defineProperty(exports, '__esModule', { value: true });"
171173 ] ) ) ;
172174 buf . push ( "};" ) ;
173175
174176 buf . push ( "" ) ;
175177 buf . push ( "// getDefaultExport function for compatibility with non-harmony modules" ) ;
176178 buf . push ( this . requireFn + ".n = function(module) {" ) ;
177- buf . push ( this . indent ( [
179+ buf . push ( Template . indent ( [
178180 "var getter = module && module.__esModule ?" ,
179- this . indent ( [
181+ Template . indent ( [
180182 "function getDefault() { return module['default']; } :" ,
181183 "function getModuleExports() { return module; };"
182184 ] ) ,
@@ -195,7 +197,7 @@ module.exports = class MainTemplate extends Template {
195197 buf . push ( "" ) ;
196198 buf . push ( "// __webpack_public_path__" ) ;
197199 buf . push ( `${ this . requireFn } .p = ${ JSON . stringify ( publicPath ) } ;` ) ;
198- return this . asString ( buf ) ;
200+ return Template . asString ( buf ) ;
199201 } ) ;
200202
201203 this . requireFn = "__webpack_require__" ;
@@ -243,13 +245,13 @@ module.exports = class MainTemplate extends Template {
243245 buf . push ( "" ) ;
244246 buf . push ( "// The require function" ) ;
245247 buf . push ( `function ${ this . requireFn } (moduleId) {` ) ;
246- buf . push ( this . indent ( this . hooks . require . call ( "" , chunk , hash ) ) ) ;
248+ buf . push ( Template . indent ( this . hooks . require . call ( "" , chunk , hash ) ) ) ;
247249 buf . push ( "}" ) ;
248250 buf . push ( "" ) ;
249- buf . push ( this . asString ( this . hooks . requireExtensions . call ( "" , chunk , hash ) ) ) ;
251+ buf . push ( Template . asString ( this . hooks . requireExtensions . call ( "" , chunk , hash ) ) ) ;
250252 buf . push ( "" ) ;
251- buf . push ( this . asString ( this . hooks . startup . call ( "" , chunk , hash ) ) ) ;
252- let source = this . hooks . render . call ( new OriginalSource ( this . prefix ( buf , " \t" ) + "\n" , `webpack/bootstrap ${ hash } ` ) , chunk , hash , moduleTemplate , dependencyTemplates ) ;
253+ buf . push ( Template . asString ( this . hooks . startup . call ( "" , chunk , hash ) ) ) ;
254+ let source = this . hooks . render . call ( new OriginalSource ( Template . prefix ( buf , " \t" ) + "\n" , `webpack/bootstrap ${ hash } ` ) , chunk , hash , moduleTemplate , dependencyTemplates ) ;
253255 if ( chunk . hasEntryModule ( ) ) {
254256 source = this . hooks . renderWithEntry . call ( source , chunk , hash ) ;
255257 }
0 commit comments