webpack 4.1.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +719 -721
  2. package/bin/webpack.js +69 -10
  3. package/lib/APIPlugin.js +84 -84
  4. package/lib/AmdMainTemplatePlugin.js +75 -77
  5. package/lib/AsyncDependencyToInitialChunkError.js +21 -23
  6. package/lib/BannerPlugin.js +101 -101
  7. package/lib/Chunk.js +477 -469
  8. package/lib/ChunkTemplate.js +51 -53
  9. package/lib/Compilation.js +1858 -1851
  10. package/lib/Compiler.js +493 -478
  11. package/lib/ConcurrentCompilationError.js +19 -0
  12. package/lib/ContextModule.js +696 -685
  13. package/lib/ContextModuleFactory.js +245 -243
  14. package/lib/DefinePlugin.js +197 -197
  15. package/lib/DelegatedModule.js +101 -101
  16. package/lib/DependenciesBlockVariable.js +51 -52
  17. package/lib/Dependency.js +53 -52
  18. package/lib/DllModule.js +54 -54
  19. package/lib/DllModuleFactory.js +29 -29
  20. package/lib/EnvironmentPlugin.js +65 -67
  21. package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
  22. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
  23. package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
  24. package/lib/ExternalModule.js +159 -159
  25. package/lib/FunctionModuleTemplatePlugin.js +98 -98
  26. package/lib/HotModuleReplacement.runtime.js +631 -631
  27. package/lib/HotModuleReplacementPlugin.js +407 -406
  28. package/lib/HotUpdateChunkTemplate.js +78 -80
  29. package/lib/JavascriptGenerator.js +228 -229
  30. package/lib/JavascriptModulesPlugin.js +184 -158
  31. package/lib/JsonGenerator.js +42 -42
  32. package/lib/MainTemplate.js +406 -402
  33. package/lib/Module.js +343 -340
  34. package/lib/ModuleBuildError.js +42 -42
  35. package/lib/ModuleError.js +28 -28
  36. package/lib/ModuleFilenameHelpers.js +166 -166
  37. package/lib/ModuleTemplate.js +77 -79
  38. package/lib/ModuleWarning.js +30 -30
  39. package/lib/MultiCompiler.js +271 -259
  40. package/lib/MultiModule.js +78 -75
  41. package/lib/MultiModuleFactory.js +23 -23
  42. package/lib/MultiWatching.js +38 -37
  43. package/lib/NoModeWarning.js +23 -21
  44. package/lib/NormalModule.js +478 -470
  45. package/lib/NormalModuleFactory.js +483 -481
  46. package/lib/OptionsDefaulter.js +80 -86
  47. package/lib/Parser.js +2074 -2071
  48. package/lib/ProgressPlugin.js +231 -231
  49. package/lib/RawModule.js +54 -55
  50. package/lib/RecordIdsPlugin.js +160 -160
  51. package/lib/RemovedPluginError.js +13 -13
  52. package/lib/ResolverFactory.js +64 -67
  53. package/lib/RuntimeTemplate.js +267 -297
  54. package/lib/SetVarMainTemplatePlugin.js +57 -57
  55. package/lib/SourceMapDevToolPlugin.js +302 -308
  56. package/lib/Stats.js +1234 -1212
  57. package/lib/Template.js +205 -205
  58. package/lib/TemplatedPathPlugin.js +170 -143
  59. package/lib/UmdMainTemplatePlugin.js +264 -269
  60. package/lib/Watching.js +193 -193
  61. package/lib/WebAssemblyParser.js +50 -54
  62. package/lib/WebpackOptionsApply.js +401 -401
  63. package/lib/WebpackOptionsDefaulter.js +337 -317
  64. package/lib/WebpackOptionsValidationError.js +316 -319
  65. package/lib/debug/ProfilingPlugin.js +409 -405
  66. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
  67. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  68. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
  69. package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
  70. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
  71. package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
  72. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
  74. package/lib/dependencies/ImportDependenciesBlock.js +17 -17
  75. package/lib/dependencies/ImportDependency.js +34 -34
  76. package/lib/dependencies/ImportEagerDependency.js +32 -32
  77. package/lib/dependencies/ImportParserPlugin.js +175 -179
  78. package/lib/dependencies/ImportWeakDependency.js +34 -34
  79. package/lib/dependencies/JsonExportsDependency.js +25 -25
  80. package/lib/dependencies/ModuleDependency.js +20 -20
  81. package/lib/dependencies/NullDependency.js +20 -20
  82. package/lib/dependencies/RequireContextDependency.js +22 -22
  83. package/lib/dependencies/RequireIncludeDependency.js +40 -40
  84. package/lib/dependencies/WebpackMissingModule.js +20 -22
  85. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  86. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  87. package/lib/node/NodeMainTemplatePlugin.js +320 -273
  88. package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
  89. package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
  90. package/lib/optimize/ConcatenatedModule.js +1364 -1366
  91. package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
  92. package/lib/optimize/SplitChunksPlugin.js +519 -491
  93. package/lib/performance/SizeLimitsPlugin.js +105 -105
  94. package/lib/util/TrackingSet.js +35 -35
  95. package/lib/util/objectToMap.js +10 -10
  96. package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
  97. package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
  98. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  99. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  100. package/lib/web/JsonpMainTemplatePlugin.js +425 -403
  101. package/lib/webpack.js +182 -179
  102. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  103. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  104. package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
  105. package/package.json +9 -8
  106. package/schemas/WebpackOptions.json +1973 -1951
  107. package/schemas/ajv.absolutePath.js +55 -29
  108. package/schemas/plugins/BannerPlugin.json +85 -85
  109. package/schemas/plugins/DllPlugin.json +28 -28
  110. package/schemas/plugins/DllReferencePlugin.json +99 -99
  111. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  112. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  113. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  114. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  115. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  116. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  117. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  118. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,269 +1,264 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const ConcatSource = require("webpack-sources").ConcatSource;
8
- const OriginalSource = require("webpack-sources").OriginalSource;
9
- const Template = require("./Template");
10
-
11
- function accessorToObjectAccess(accessor) {
12
- return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
13
- }
14
-
15
- function accessorAccess(base, accessor) {
16
- accessor = [].concat(accessor);
17
- return accessor
18
- .map((a, idx) => {
19
- a = base + accessorToObjectAccess(accessor.slice(0, idx + 1));
20
- if (idx === accessor.length - 1) return a;
21
- return `${a} = ${a} || {}`;
22
- })
23
- .join(", ");
24
- }
25
-
26
- class UmdMainTemplatePlugin {
27
- constructor(name, options) {
28
- if (typeof name === "object" && !Array.isArray(name)) {
29
- this.name = name.root || name.amd || name.commonjs;
30
- this.names = name;
31
- } else {
32
- this.name = name;
33
- this.names = {
34
- commonjs: name,
35
- root: name,
36
- amd: name
37
- };
38
- }
39
- this.optionalAmdExternalAsGlobal = options.optionalAmdExternalAsGlobal;
40
- this.namedDefine = options.namedDefine;
41
- this.auxiliaryComment = options.auxiliaryComment;
42
- }
43
-
44
- apply(compilation) {
45
- const { mainTemplate, chunkTemplate, runtimeTemplate } = compilation;
46
-
47
- const onRenderWithEntry = (source, chunk, hash) => {
48
- let externals = chunk
49
- .getModules()
50
- .filter(
51
- m =>
52
- m.external &&
53
- (m.externalType === "umd" || m.externalType === "umd2")
54
- );
55
- const optionalExternals = [];
56
- let requiredExternals = [];
57
- if (this.optionalAmdExternalAsGlobal) {
58
- for (const m of externals) {
59
- if (m.optional) {
60
- optionalExternals.push(m);
61
- } else {
62
- requiredExternals.push(m);
63
- }
64
- }
65
- externals = requiredExternals.concat(optionalExternals);
66
- } else {
67
- requiredExternals = externals;
68
- }
69
-
70
- function replaceKeys(str) {
71
- return mainTemplate.getAssetPath(str, {
72
- hash,
73
- chunk
74
- });
75
- }
76
-
77
- function externalsDepsArray(modules) {
78
- return `[${replaceKeys(
79
- modules
80
- .map(m =>
81
- JSON.stringify(
82
- typeof m.request === "object" ? m.request.amd : m.request
83
- )
84
- )
85
- .join(", ")
86
- )}]`;
87
- }
88
-
89
- function externalsRootArray(modules) {
90
- return replaceKeys(
91
- modules
92
- .map(m => {
93
- let request = m.request;
94
- if (typeof request === "object") request = request.root;
95
- return `root${accessorToObjectAccess([].concat(request))}`;
96
- })
97
- .join(", ")
98
- );
99
- }
100
-
101
- function externalsRequireArray(type) {
102
- return replaceKeys(
103
- externals
104
- .map(m => {
105
- let expr;
106
- let request = m.request;
107
- if (typeof request === "object") request = request[type];
108
- if (typeof request === "undefined")
109
- throw new Error(
110
- "Missing external configuration for type:" + type
111
- );
112
- if (Array.isArray(request)) {
113
- expr = `require(${JSON.stringify(
114
- request[0]
115
- )})${accessorToObjectAccess(request.slice(1))}`;
116
- } else expr = `require(${JSON.stringify(request)})`;
117
- if (m.optional) {
118
- expr = `(function webpackLoadOptionalExternalModule() { try { return ${
119
- expr
120
- }; } catch(e) {} }())`;
121
- }
122
- return expr;
123
- })
124
- .join(", ")
125
- );
126
- }
127
-
128
- function externalsArguments(modules) {
129
- return modules
130
- .map(
131
- m =>
132
- `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(`${m.id}`)}__`
133
- )
134
- .join(", ");
135
- }
136
-
137
- function libraryName(library) {
138
- return JSON.stringify(replaceKeys([].concat(library).pop()));
139
- }
140
-
141
- let amdFactory;
142
- if (optionalExternals.length > 0) {
143
- const wrapperArguments = externalsArguments(requiredExternals);
144
- const factoryArguments =
145
- requiredExternals.length > 0
146
- ? externalsArguments(requiredExternals) +
147
- ", " +
148
- externalsRootArray(optionalExternals)
149
- : externalsRootArray(optionalExternals);
150
- amdFactory =
151
- `function webpackLoadOptionalExternalModuleAmd(${
152
- wrapperArguments
153
- }) {\n` +
154
- ` return factory(${factoryArguments});\n` +
155
- " }";
156
- } else {
157
- amdFactory = "factory";
158
- }
159
-
160
- return new ConcatSource(
161
- new OriginalSource(
162
- "(function webpackUniversalModuleDefinition(root, factory) {\n" +
163
- (this.auxiliaryComment && typeof this.auxiliaryComment === "string"
164
- ? " //" + this.auxiliaryComment + "\n"
165
- : this.auxiliaryComment.commonjs2
166
- ? " //" + this.auxiliaryComment.commonjs2 + "\n"
167
- : "") +
168
- " if(typeof exports === 'object' && typeof module === 'object')\n" +
169
- " module.exports = factory(" +
170
- externalsRequireArray("commonjs2") +
171
- ");\n" +
172
- (this.auxiliaryComment && typeof this.auxiliaryComment === "string"
173
- ? " //" + this.auxiliaryComment + "\n"
174
- : this.auxiliaryComment.amd
175
- ? " //" + this.auxiliaryComment.amd + "\n"
176
- : "") +
177
- " else if(typeof define === 'function' && define.amd)\n" +
178
- (requiredExternals.length > 0
179
- ? this.names.amd && this.namedDefine === true
180
- ? " define(" +
181
- libraryName(this.names.amd) +
182
- ", " +
183
- externalsDepsArray(requiredExternals) +
184
- ", " +
185
- amdFactory +
186
- ");\n"
187
- : " define(" +
188
- externalsDepsArray(requiredExternals) +
189
- ", " +
190
- amdFactory +
191
- ");\n"
192
- : this.names.amd && this.namedDefine === true
193
- ? " define(" +
194
- libraryName(this.names.amd) +
195
- ", [], " +
196
- amdFactory +
197
- ");\n"
198
- : " define([], " + amdFactory + ");\n") +
199
- (this.names.root || this.names.commonjs
200
- ? (this.auxiliaryComment &&
201
- typeof this.auxiliaryComment === "string"
202
- ? " //" + this.auxiliaryComment + "\n"
203
- : this.auxiliaryComment.commonjs
204
- ? " //" + this.auxiliaryComment.commonjs + "\n"
205
- : "") +
206
- " else if(typeof exports === 'object')\n" +
207
- " exports[" +
208
- libraryName(this.names.commonjs || this.names.root) +
209
- "] = factory(" +
210
- externalsRequireArray("commonjs") +
211
- ");\n" +
212
- (this.auxiliaryComment &&
213
- typeof this.auxiliaryComment === "string"
214
- ? " //" + this.auxiliaryComment + "\n"
215
- : this.auxiliaryComment.root
216
- ? " //" + this.auxiliaryComment.root + "\n"
217
- : "") +
218
- " else\n" +
219
- " " +
220
- replaceKeys(
221
- accessorAccess("root", this.names.root || this.names.commonjs)
222
- ) +
223
- " = factory(" +
224
- externalsRootArray(externals) +
225
- ");\n"
226
- : " else {\n" +
227
- (externals.length > 0
228
- ? " var a = typeof exports === 'object' ? factory(" +
229
- externalsRequireArray("commonjs") +
230
- ") : factory(" +
231
- externalsRootArray(externals) +
232
- ");\n"
233
- : " var a = factory();\n") +
234
- " for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
235
- " }\n") +
236
- `})(${
237
- runtimeTemplate.outputOptions.globalObject
238
- }, function(${externalsArguments(externals)}) {\nreturn `,
239
- "webpack/universalModuleDefinition"
240
- ),
241
- source,
242
- ";\n})"
243
- );
244
- };
245
-
246
- for (const template of [mainTemplate, chunkTemplate]) {
247
- template.hooks.renderWithEntry.tap(
248
- "UmdMainTemplatePlugin",
249
- onRenderWithEntry
250
- );
251
- }
252
-
253
- mainTemplate.hooks.globalHashPaths.tap("UmdMainTemplatePlugin", paths => {
254
- if (this.names.root) paths = paths.concat(this.names.root);
255
- if (this.names.amd) paths = paths.concat(this.names.amd);
256
- if (this.names.commonjs) paths = paths.concat(this.names.commonjs);
257
- return paths;
258
- });
259
-
260
- mainTemplate.hooks.hash.tap("UmdMainTemplatePlugin", hash => {
261
- hash.update("umd");
262
- hash.update(`${this.names.root}`);
263
- hash.update(`${this.names.amd}`);
264
- hash.update(`${this.names.commonjs}`);
265
- });
266
- }
267
- }
268
-
269
- module.exports = UmdMainTemplatePlugin;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const { ConcatSource, OriginalSource } = require("webpack-sources");
8
+ const Template = require("./Template");
9
+
10
+ function accessorToObjectAccess(accessor) {
11
+ return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
12
+ }
13
+
14
+ function accessorAccess(base, accessor) {
15
+ accessor = [].concat(accessor);
16
+ return accessor
17
+ .map((a, idx) => {
18
+ a = base + accessorToObjectAccess(accessor.slice(0, idx + 1));
19
+ if (idx === accessor.length - 1) return a;
20
+ return `${a} = ${a} || {}`;
21
+ })
22
+ .join(", ");
23
+ }
24
+
25
+ class UmdMainTemplatePlugin {
26
+ constructor(name, options) {
27
+ if (typeof name === "object" && !Array.isArray(name)) {
28
+ this.name = name.root || name.amd || name.commonjs;
29
+ this.names = name;
30
+ } else {
31
+ this.name = name;
32
+ this.names = {
33
+ commonjs: name,
34
+ root: name,
35
+ amd: name
36
+ };
37
+ }
38
+ this.optionalAmdExternalAsGlobal = options.optionalAmdExternalAsGlobal;
39
+ this.namedDefine = options.namedDefine;
40
+ this.auxiliaryComment = options.auxiliaryComment;
41
+ }
42
+
43
+ apply(compilation) {
44
+ const { mainTemplate, chunkTemplate, runtimeTemplate } = compilation;
45
+
46
+ const onRenderWithEntry = (source, chunk, hash) => {
47
+ let externals = chunk
48
+ .getModules()
49
+ .filter(
50
+ m =>
51
+ m.external &&
52
+ (m.externalType === "umd" || m.externalType === "umd2")
53
+ );
54
+ const optionalExternals = [];
55
+ let requiredExternals = [];
56
+ if (this.optionalAmdExternalAsGlobal) {
57
+ for (const m of externals) {
58
+ if (m.optional) {
59
+ optionalExternals.push(m);
60
+ } else {
61
+ requiredExternals.push(m);
62
+ }
63
+ }
64
+ externals = requiredExternals.concat(optionalExternals);
65
+ } else {
66
+ requiredExternals = externals;
67
+ }
68
+
69
+ function replaceKeys(str) {
70
+ return mainTemplate.getAssetPath(str, {
71
+ hash,
72
+ chunk
73
+ });
74
+ }
75
+
76
+ function externalsDepsArray(modules) {
77
+ return `[${replaceKeys(
78
+ modules
79
+ .map(m =>
80
+ JSON.stringify(
81
+ typeof m.request === "object" ? m.request.amd : m.request
82
+ )
83
+ )
84
+ .join(", ")
85
+ )}]`;
86
+ }
87
+
88
+ function externalsRootArray(modules) {
89
+ return replaceKeys(
90
+ modules
91
+ .map(m => {
92
+ let request = m.request;
93
+ if (typeof request === "object") request = request.root;
94
+ return `root${accessorToObjectAccess([].concat(request))}`;
95
+ })
96
+ .join(", ")
97
+ );
98
+ }
99
+
100
+ function externalsRequireArray(type) {
101
+ return replaceKeys(
102
+ externals
103
+ .map(m => {
104
+ let expr;
105
+ let request = m.request;
106
+ if (typeof request === "object") request = request[type];
107
+ if (typeof request === "undefined")
108
+ throw new Error(
109
+ "Missing external configuration for type:" + type
110
+ );
111
+ if (Array.isArray(request)) {
112
+ expr = `require(${JSON.stringify(
113
+ request[0]
114
+ )})${accessorToObjectAccess(request.slice(1))}`;
115
+ } else expr = `require(${JSON.stringify(request)})`;
116
+ if (m.optional) {
117
+ expr = `(function webpackLoadOptionalExternalModule() { try { return ${expr}; } catch(e) {} }())`;
118
+ }
119
+ return expr;
120
+ })
121
+ .join(", ")
122
+ );
123
+ }
124
+
125
+ function externalsArguments(modules) {
126
+ return modules
127
+ .map(
128
+ m =>
129
+ `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(`${m.id}`)}__`
130
+ )
131
+ .join(", ");
132
+ }
133
+
134
+ function libraryName(library) {
135
+ return JSON.stringify(replaceKeys([].concat(library).pop()));
136
+ }
137
+
138
+ let amdFactory;
139
+ if (optionalExternals.length > 0) {
140
+ const wrapperArguments = externalsArguments(requiredExternals);
141
+ const factoryArguments =
142
+ requiredExternals.length > 0
143
+ ? externalsArguments(requiredExternals) +
144
+ ", " +
145
+ externalsRootArray(optionalExternals)
146
+ : externalsRootArray(optionalExternals);
147
+ amdFactory =
148
+ `function webpackLoadOptionalExternalModuleAmd(${wrapperArguments}) {\n` +
149
+ ` return factory(${factoryArguments});\n` +
150
+ " }";
151
+ } else {
152
+ amdFactory = "factory";
153
+ }
154
+
155
+ return new ConcatSource(
156
+ new OriginalSource(
157
+ "(function webpackUniversalModuleDefinition(root, factory) {\n" +
158
+ (this.auxiliaryComment && typeof this.auxiliaryComment === "string"
159
+ ? " //" + this.auxiliaryComment + "\n"
160
+ : this.auxiliaryComment.commonjs2
161
+ ? " //" + this.auxiliaryComment.commonjs2 + "\n"
162
+ : "") +
163
+ " if(typeof exports === 'object' && typeof module === 'object')\n" +
164
+ " module.exports = factory(" +
165
+ externalsRequireArray("commonjs2") +
166
+ ");\n" +
167
+ (this.auxiliaryComment && typeof this.auxiliaryComment === "string"
168
+ ? " //" + this.auxiliaryComment + "\n"
169
+ : this.auxiliaryComment.amd
170
+ ? " //" + this.auxiliaryComment.amd + "\n"
171
+ : "") +
172
+ " else if(typeof define === 'function' && define.amd)\n" +
173
+ (requiredExternals.length > 0
174
+ ? this.names.amd && this.namedDefine === true
175
+ ? " define(" +
176
+ libraryName(this.names.amd) +
177
+ ", " +
178
+ externalsDepsArray(requiredExternals) +
179
+ ", " +
180
+ amdFactory +
181
+ ");\n"
182
+ : " define(" +
183
+ externalsDepsArray(requiredExternals) +
184
+ ", " +
185
+ amdFactory +
186
+ ");\n"
187
+ : this.names.amd && this.namedDefine === true
188
+ ? " define(" +
189
+ libraryName(this.names.amd) +
190
+ ", [], " +
191
+ amdFactory +
192
+ ");\n"
193
+ : " define([], " + amdFactory + ");\n") +
194
+ (this.names.root || this.names.commonjs
195
+ ? (this.auxiliaryComment &&
196
+ typeof this.auxiliaryComment === "string"
197
+ ? " //" + this.auxiliaryComment + "\n"
198
+ : this.auxiliaryComment.commonjs
199
+ ? " //" + this.auxiliaryComment.commonjs + "\n"
200
+ : "") +
201
+ " else if(typeof exports === 'object')\n" +
202
+ " exports[" +
203
+ libraryName(this.names.commonjs || this.names.root) +
204
+ "] = factory(" +
205
+ externalsRequireArray("commonjs") +
206
+ ");\n" +
207
+ (this.auxiliaryComment &&
208
+ typeof this.auxiliaryComment === "string"
209
+ ? " //" + this.auxiliaryComment + "\n"
210
+ : this.auxiliaryComment.root
211
+ ? " //" + this.auxiliaryComment.root + "\n"
212
+ : "") +
213
+ " else\n" +
214
+ " " +
215
+ replaceKeys(
216
+ accessorAccess("root", this.names.root || this.names.commonjs)
217
+ ) +
218
+ " = factory(" +
219
+ externalsRootArray(externals) +
220
+ ");\n"
221
+ : " else {\n" +
222
+ (externals.length > 0
223
+ ? " var a = typeof exports === 'object' ? factory(" +
224
+ externalsRequireArray("commonjs") +
225
+ ") : factory(" +
226
+ externalsRootArray(externals) +
227
+ ");\n"
228
+ : " var a = factory();\n") +
229
+ " for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
230
+ " }\n") +
231
+ `})(${
232
+ runtimeTemplate.outputOptions.globalObject
233
+ }, function(${externalsArguments(externals)}) {\nreturn `,
234
+ "webpack/universalModuleDefinition"
235
+ ),
236
+ source,
237
+ ";\n})"
238
+ );
239
+ };
240
+
241
+ for (const template of [mainTemplate, chunkTemplate]) {
242
+ template.hooks.renderWithEntry.tap(
243
+ "UmdMainTemplatePlugin",
244
+ onRenderWithEntry
245
+ );
246
+ }
247
+
248
+ mainTemplate.hooks.globalHashPaths.tap("UmdMainTemplatePlugin", paths => {
249
+ if (this.names.root) paths = paths.concat(this.names.root);
250
+ if (this.names.amd) paths = paths.concat(this.names.amd);
251
+ if (this.names.commonjs) paths = paths.concat(this.names.commonjs);
252
+ return paths;
253
+ });
254
+
255
+ mainTemplate.hooks.hash.tap("UmdMainTemplatePlugin", hash => {
256
+ hash.update("umd");
257
+ hash.update(`${this.names.root}`);
258
+ hash.update(`${this.names.amd}`);
259
+ hash.update(`${this.names.commonjs}`);
260
+ });
261
+ }
262
+ }
263
+
264
+ module.exports = UmdMainTemplatePlugin;