webpack 2.3.3 → 2.5.1

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 (81) hide show
  1. package/README.md +148 -133
  2. package/lib/APIPlugin.js +0 -6
  3. package/lib/AsyncDependenciesBlock.js +1 -1
  4. package/lib/AutomaticPrefetchPlugin.js +2 -2
  5. package/lib/BannerPlugin.js +30 -8
  6. package/lib/CachePlugin.js +2 -2
  7. package/lib/CaseSensitiveModulesWarning.js +6 -3
  8. package/lib/ChunkRenderError.js +3 -1
  9. package/lib/ChunkTemplate.js +2 -2
  10. package/lib/Compilation.js +17 -17
  11. package/lib/Compiler.js +30 -25
  12. package/lib/ContextModule.js +4 -3
  13. package/lib/ContextModuleFactory.js +5 -5
  14. package/lib/DelegatedModule.js +69 -63
  15. package/lib/DependenciesBlock.js +65 -59
  16. package/lib/Dependency.js +1 -0
  17. package/lib/EntryModuleNotFoundError.js +16 -10
  18. package/lib/ExtendedAPIPlugin.js +7 -2
  19. package/lib/ExternalModule.js +1 -1
  20. package/lib/ExternalModuleFactoryPlugin.js +26 -23
  21. package/lib/FlagDependencyUsagePlugin.js +63 -75
  22. package/lib/HotModuleReplacement.runtime.js +25 -27
  23. package/lib/HotModuleReplacementPlugin.js +3 -5
  24. package/lib/IgnorePlugin.js +48 -17
  25. package/lib/JsonpChunkTemplatePlugin.js +24 -24
  26. package/lib/JsonpMainTemplatePlugin.js +182 -182
  27. package/lib/LibManifestPlugin.js +51 -46
  28. package/lib/MainTemplate.js +17 -18
  29. package/lib/Module.js +158 -160
  30. package/lib/ModuleBuildError.js +4 -2
  31. package/lib/ModuleDependencyError.js +2 -1
  32. package/lib/ModuleDependencyWarning.js +2 -1
  33. package/lib/ModuleError.js +2 -2
  34. package/lib/ModuleFilenameHelpers.js +27 -27
  35. package/lib/ModuleNotFoundError.js +3 -1
  36. package/lib/ModuleParseError.js +6 -4
  37. package/lib/ModuleWarning.js +2 -2
  38. package/lib/MultiCompiler.js +3 -4
  39. package/lib/MultiStats.js +3 -3
  40. package/lib/MultiWatching.js +2 -2
  41. package/lib/NamedChunksPlugin.js +30 -0
  42. package/lib/NodeStuffPlugin.js +80 -79
  43. package/lib/NormalModule.js +7 -3
  44. package/lib/NormalModuleFactory.js +244 -240
  45. package/lib/Parser.js +1256 -1079
  46. package/lib/ProgressPlugin.js +2 -2
  47. package/lib/RawModule.js +1 -1
  48. package/lib/RecordIdsPlugin.js +5 -9
  49. package/lib/SetVarMainTemplatePlugin.js +1 -1
  50. package/lib/SourceMapDevToolPlugin.js +153 -157
  51. package/lib/Stats.js +34 -6
  52. package/lib/TemplatedPathPlugin.js +1 -0
  53. package/lib/UnsupportedFeatureWarning.js +2 -1
  54. package/lib/WebpackError.js +11 -0
  55. package/lib/WebpackOptionsApply.js +4 -4
  56. package/lib/WebpackOptionsValidationError.js +2 -3
  57. package/lib/dependencies/AMDDefineDependency.js +10 -6
  58. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -1
  59. package/lib/dependencies/AMDPlugin.js +3 -3
  60. package/lib/dependencies/ContextDependencyHelpers.js +19 -16
  61. package/lib/dependencies/CriticalDependencyWarning.js +4 -1
  62. package/lib/dependencies/DepBlockHelpers.js +3 -3
  63. package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
  64. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  65. package/lib/dependencies/ImportContextDependency.js +2 -1
  66. package/lib/dependencies/ImportDependenciesBlock.js +2 -2
  67. package/lib/dependencies/ImportParserPlugin.js +16 -2
  68. package/lib/dependencies/RequireEnsureDependenciesBlock.js +11 -3
  69. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +42 -13
  70. package/lib/dependencies/RequireEnsureDependency.js +9 -2
  71. package/lib/formatLocation.js +44 -27
  72. package/lib/optimize/AggressiveSplittingPlugin.js +10 -17
  73. package/lib/optimize/CommonsChunkPlugin.js +2 -2
  74. package/lib/performance/AssetsOverSizeLimitWarning.js +4 -1
  75. package/lib/performance/EntrypointsOverSizeLimitWarning.js +5 -1
  76. package/lib/performance/NoAsyncChunksWarning.js +5 -1
  77. package/lib/removeAndDo.js +6 -4
  78. package/lib/util/identifier.js +16 -0
  79. package/lib/webpack.js +2 -1
  80. package/package.json +7 -4
  81. package/schemas/webpackOptionsSchema.json +35 -0
@@ -2,207 +2,207 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var Template = require("./Template");
5
+ "use strict";
6
6
 
7
- function JsonpMainTemplatePlugin() {}
8
- module.exports = JsonpMainTemplatePlugin;
7
+ const Template = require("./Template");
9
8
 
10
- JsonpMainTemplatePlugin.prototype.constructor = JsonpMainTemplatePlugin;
11
- JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
12
- mainTemplate.plugin("local-vars", function(source, chunk) {
13
- if(chunk.chunks.length > 0) {
14
- return this.asString([
15
- source,
16
- "",
17
- "// objects to store loaded and loading chunks",
18
- "var installedChunks = {",
19
- this.indent(
20
- chunk.ids.map(function(id) {
21
- return id + ": 0";
22
- }).join(",\n")
23
- ),
24
- "};"
25
- ]);
26
- }
27
- return source;
28
- });
29
- mainTemplate.plugin("jsonp-script", function(_, chunk, hash) {
30
- var chunkFilename = this.outputOptions.chunkFilename;
31
- var chunkMaps = chunk.getChunkMaps();
32
- var crossOriginLoading = this.outputOptions.crossOriginLoading;
33
- var chunkLoadTimeout = this.outputOptions.chunkLoadTimeout || 120000;
34
- return this.asString([
35
- "var script = document.createElement('script');",
36
- "script.type = 'text/javascript';",
37
- "script.charset = 'utf-8';",
38
- "script.async = true;",
39
- "script.timeout = " + chunkLoadTimeout + ";",
40
- crossOriginLoading ? "script.crossOrigin = '" + crossOriginLoading + "';" : "",
41
- "if (" + this.requireFn + ".nc) {",
42
- this.indent("script.setAttribute(\"nonce\", " + this.requireFn + ".nc);"),
43
- "}",
44
- "script.src = " + this.requireFn + ".p + " +
45
- this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
46
- hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
47
- hashWithLength: function(length) {
48
- return "\" + " + this.renderCurrentHashCode(hash, length) + " + \"";
49
- }.bind(this),
9
+ class JsonpMainTemplatePlugin {
10
+
11
+ apply(mainTemplate) {
12
+ mainTemplate.plugin("local-vars", function(source, chunk) {
13
+ if(chunk.chunks.length > 0) {
14
+ return this.asString([
15
+ source,
16
+ "",
17
+ "// objects to store loaded and loading chunks",
18
+ "var installedChunks = {",
19
+ this.indent(
20
+ chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n")
21
+ ),
22
+ "};"
23
+ ]);
24
+ }
25
+ return source;
26
+ });
27
+ mainTemplate.plugin("jsonp-script", function(_, chunk, hash) {
28
+ const chunkFilename = this.outputOptions.chunkFilename;
29
+ const chunkMaps = chunk.getChunkMaps();
30
+ const crossOriginLoading = this.outputOptions.crossOriginLoading;
31
+ const chunkLoadTimeout = this.outputOptions.chunkLoadTimeout || 120000;
32
+ const scriptSrcPath = this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
33
+ hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
34
+ hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
50
35
  chunk: {
51
36
  id: "\" + chunkId + \"",
52
- hash: "\" + " + JSON.stringify(chunkMaps.hash) + "[chunkId] + \"",
53
- hashWithLength: function(length) {
54
- var shortChunkHashMap = {};
55
- Object.keys(chunkMaps.hash).forEach(function(chunkId) {
37
+ hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
38
+ hashWithLength(length) {
39
+ const shortChunkHashMap = Object.create(null);
40
+ Object.keys(chunkMaps.hash).forEach(chunkId => {
56
41
  if(typeof chunkMaps.hash[chunkId] === "string")
57
42
  shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
58
43
  });
59
- return "\" + " + JSON.stringify(shortChunkHashMap) + "[chunkId] + \"";
44
+ return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
60
45
  },
61
- name: "\" + (" + JSON.stringify(chunkMaps.name) + "[chunkId]||chunkId) + \""
46
+ name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
62
47
  }
63
- }) + ";",
64
- "var timeout = setTimeout(onScriptComplete, " + chunkLoadTimeout + ");",
65
- "script.onerror = script.onload = onScriptComplete;",
66
- "function onScriptComplete() {",
67
- this.indent([
68
- "// avoid mem leaks in IE.",
69
- "script.onerror = script.onload = null;",
70
- "clearTimeout(timeout);",
71
- "var chunk = installedChunks[chunkId];",
72
- "if(chunk !== 0) {",
48
+ });
49
+ return this.asString([
50
+ "var script = document.createElement('script');",
51
+ "script.type = 'text/javascript';",
52
+ "script.charset = 'utf-8';",
53
+ "script.async = true;",
54
+ `script.timeout = ${chunkLoadTimeout};`,
55
+ crossOriginLoading ? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)};` : "",
56
+ `if (${this.requireFn}.nc) {`,
57
+ this.indent(`script.setAttribute("nonce", ${this.requireFn}.nc);`),
58
+ "}",
59
+ `script.src = ${this.requireFn}.p + ${scriptSrcPath};`,
60
+ `var timeout = setTimeout(onScriptComplete, ${chunkLoadTimeout});`,
61
+ "script.onerror = script.onload = onScriptComplete;",
62
+ "function onScriptComplete() {",
73
63
  this.indent([
74
- "if(chunk) chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));",
75
- "installedChunks[chunkId] = undefined;"
64
+ "// avoid mem leaks in IE.",
65
+ "script.onerror = script.onload = null;",
66
+ "clearTimeout(timeout);",
67
+ "var chunk = installedChunks[chunkId];",
68
+ "if(chunk !== 0) {",
69
+ this.indent([
70
+ "if(chunk) {",
71
+ this.indent("chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));"),
72
+ "}",
73
+ "installedChunks[chunkId] = undefined;"
74
+ ]),
75
+ "}"
76
76
  ]),
77
- "}"
78
- ]),
79
- "};",
80
- ]);
81
- });
82
- mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
83
- return this.asString([
84
- "if(installedChunks[chunkId] === 0)",
85
- this.indent([
86
- "return Promise.resolve();"
87
- ]),
88
- "",
89
- "// a Promise means \"currently loading\".",
90
- "if(installedChunks[chunkId]) {",
91
- this.indent([
92
- "return installedChunks[chunkId][2];"
93
- ]),
94
- "}",
95
- "",
96
- "// setup Promise in chunk cache",
97
- "var promise = new Promise(function(resolve, reject) {",
98
- this.indent([
99
- "installedChunks[chunkId] = [resolve, reject];"
100
- ]),
101
- "});",
102
- "installedChunks[chunkId][2] = promise;",
103
- "",
104
- "// start chunk loading",
105
- "var head = document.getElementsByTagName('head')[0];",
106
- this.applyPluginsWaterfall("jsonp-script", "", chunk, hash),
107
- "head.appendChild(script);",
108
- "",
109
- "return promise;"
110
- ]);
111
- });
112
- mainTemplate.plugin("require-extensions", function(source, chunk) {
113
- if(chunk.chunks.length === 0) return source;
114
- return this.asString([
115
- source,
116
- "",
117
- "// on error function for async loading",
118
- this.requireFn + ".oe = function(err) { console.error(err); throw err; };"
119
- ]);
120
- });
121
- mainTemplate.plugin("bootstrap", function(source, chunk, hash) {
122
- if(chunk.chunks.length > 0) {
123
- var jsonpFunction = this.outputOptions.jsonpFunction;
77
+ "};",
78
+ ]);
79
+ });
80
+ mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
124
81
  return this.asString([
125
- source,
82
+ "if(installedChunks[chunkId] === 0) {",
83
+ this.indent([
84
+ "return Promise.resolve();"
85
+ ]),
86
+ "}",
126
87
  "",
127
- "// install a JSONP callback for chunk loading",
128
- "var parentJsonpFunction = window[" + JSON.stringify(jsonpFunction) + "];",
129
- "window[" + JSON.stringify(jsonpFunction) + "] = function webpackJsonpCallback(chunkIds, moreModules, executeModules) {",
88
+ "// a Promise means \"currently loading\".",
89
+ "if(installedChunks[chunkId]) {",
130
90
  this.indent([
131
- "// add \"moreModules\" to the modules object,",
132
- "// then flag all \"chunkIds\" as loaded and fire callback",
133
- "var moduleId, chunkId, i = 0, resolves = [], result;",
134
- "for(;i < chunkIds.length; i++) {",
135
- this.indent([
136
- "chunkId = chunkIds[i];",
137
- "if(installedChunks[chunkId])",
138
- this.indent("resolves.push(installedChunks[chunkId][0]);"),
139
- "installedChunks[chunkId] = 0;"
140
- ]),
141
- "}",
142
- "for(moduleId in moreModules) {",
91
+ "return installedChunks[chunkId][2];"
92
+ ]),
93
+ "}",
94
+ "",
95
+ "// setup Promise in chunk cache",
96
+ "var promise = new Promise(function(resolve, reject) {",
97
+ this.indent([
98
+ "installedChunks[chunkId] = [resolve, reject];"
99
+ ]),
100
+ "});",
101
+ "installedChunks[chunkId][2] = promise;",
102
+ "",
103
+ "// start chunk loading",
104
+ "var head = document.getElementsByTagName('head')[0];",
105
+ this.applyPluginsWaterfall("jsonp-script", "", chunk, hash),
106
+ "head.appendChild(script);",
107
+ "",
108
+ "return promise;"
109
+ ]);
110
+ });
111
+ mainTemplate.plugin("require-extensions", function(source, chunk) {
112
+ if(chunk.chunks.length === 0) return source;
113
+
114
+ return this.asString([
115
+ source,
116
+ "",
117
+ "// on error function for async loading",
118
+ `${this.requireFn}.oe = function(err) { console.error(err); throw err; };`
119
+ ]);
120
+ });
121
+ mainTemplate.plugin("bootstrap", function(source, chunk, hash) {
122
+ if(chunk.chunks.length > 0) {
123
+ var jsonpFunction = this.outputOptions.jsonpFunction;
124
+ return this.asString([
125
+ source,
126
+ "",
127
+ "// install a JSONP callback for chunk loading",
128
+ `var parentJsonpFunction = window[${JSON.stringify(jsonpFunction)}];`,
129
+ `window[${JSON.stringify(jsonpFunction)}] = function webpackJsonpCallback(chunkIds, moreModules, executeModules) {`,
143
130
  this.indent([
144
- "if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
145
- this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")),
146
- "}"
147
- ]),
148
- "}",
149
- "if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules, executeModules);",
150
- "while(resolves.length)",
151
- this.indent("resolves.shift()();"),
152
- this.entryPointInChildren(chunk) ? [
153
- "if(executeModules) {",
131
+ "// add \"moreModules\" to the modules object,",
132
+ "// then flag all \"chunkIds\" as loaded and fire callback",
133
+ "var moduleId, chunkId, i = 0, resolves = [], result;",
134
+ "for(;i < chunkIds.length; i++) {",
154
135
  this.indent([
155
- "for(i=0; i < executeModules.length; i++) {",
156
- this.indent("result = " + this.requireFn + "(" + this.requireFn + ".s = executeModules[i]);"),
136
+ "chunkId = chunkIds[i];",
137
+ "if(installedChunks[chunkId]) {",
138
+ this.indent("resolves.push(installedChunks[chunkId][0]);"),
139
+ "}",
140
+ "installedChunks[chunkId] = 0;"
141
+ ]),
142
+ "}",
143
+ "for(moduleId in moreModules) {",
144
+ this.indent([
145
+ "if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
146
+ this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")),
157
147
  "}"
158
148
  ]),
159
149
  "}",
160
- "return result;",
161
- ] : ""
162
- ]),
163
- "};"
164
- ]);
165
- }
166
- return source;
167
- });
168
- mainTemplate.plugin("hot-bootstrap", function(source, chunk, hash) {
169
- var hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename;
170
- var hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename;
171
- var hotUpdateFunction = this.outputOptions.hotUpdateFunction;
172
- var currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), {
173
- hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
174
- hashWithLength: function(length) {
175
- return "\" + " + this.renderCurrentHashCode(hash, length) + " + \"";
176
- }.bind(this),
177
- chunk: {
178
- id: "\" + chunkId + \""
150
+ "if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules, executeModules);",
151
+ "while(resolves.length) {",
152
+ this.indent("resolves.shift()();"),
153
+ "}",
154
+ this.entryPointInChildren(chunk) ? [
155
+ "if(executeModules) {",
156
+ this.indent([
157
+ "for(i=0; i < executeModules.length; i++) {",
158
+ this.indent(`result = ${this.requireFn}(${this.requireFn}.s = executeModules[i]);`),
159
+ "}"
160
+ ]),
161
+ "}",
162
+ "return result;",
163
+ ] : ""
164
+ ]),
165
+ "};"
166
+ ]);
179
167
  }
168
+ return source;
180
169
  });
181
- var currentHotUpdateMainFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateMainFilename), {
182
- hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
183
- hashWithLength: function(length) {
184
- return "\" + " + this.renderCurrentHashCode(hash, length) + " + \"";
185
- }.bind(this)
170
+ mainTemplate.plugin("hot-bootstrap", function(source, chunk, hash) {
171
+ const hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename;
172
+ const hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename;
173
+ const hotUpdateFunction = this.outputOptions.hotUpdateFunction;
174
+ const currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), {
175
+ hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
176
+ hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
177
+ chunk: {
178
+ id: "\" + chunkId + \""
179
+ }
180
+ });
181
+ const currentHotUpdateMainFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateMainFilename), {
182
+ hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
183
+ hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`
184
+ });
185
+ const runtimeSource = Template.getFunctionContent(require("./JsonpMainTemplate.runtime.js"))
186
+ .replace(/\/\/\$semicolon/g, ";")
187
+ .replace(/\$require\$/g, this.requireFn)
188
+ .replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
189
+ .replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename)
190
+ .replace(/\$hash\$/g, JSON.stringify(hash));
191
+ return `${source}
192
+ function hotDisposeChunk(chunkId) {
193
+ delete installedChunks[chunkId];
194
+ }
195
+ var parentHotUpdateCallback = this[${JSON.stringify(hotUpdateFunction)}];
196
+ this[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
186
197
  });
187
-
188
- return source + "\n" +
189
- "function hotDisposeChunk(chunkId) {\n" +
190
- "\tdelete installedChunks[chunkId];\n" +
191
- "}\n" +
192
- "var parentHotUpdateCallback = this[" + JSON.stringify(hotUpdateFunction) + "];\n" +
193
- "this[" + JSON.stringify(hotUpdateFunction) + "] = " + Template.getFunctionContent(require("./JsonpMainTemplate.runtime.js"))
194
- .replace(/\/\/\$semicolon/g, ";")
195
- .replace(/\$require\$/g, this.requireFn)
196
- .replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
197
- .replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename)
198
- .replace(/\$hash\$/g, JSON.stringify(hash));
199
- });
200
- mainTemplate.plugin("hash", function(hash) {
201
- hash.update("jsonp");
202
- hash.update("4");
203
- hash.update(this.outputOptions.filename + "");
204
- hash.update(this.outputOptions.chunkFilename + "");
205
- hash.update(this.outputOptions.jsonpFunction + "");
206
- hash.update(this.outputOptions.hotUpdateFunction + "");
207
- });
208
- };
198
+ mainTemplate.plugin("hash", function(hash) {
199
+ hash.update("jsonp");
200
+ hash.update("4");
201
+ hash.update(`${this.outputOptions.filename}`);
202
+ hash.update(`${this.outputOptions.chunkFilename}`);
203
+ hash.update(`${this.outputOptions.jsonpFunction}`);
204
+ hash.update(`${this.outputOptions.hotUpdateFunction}`);
205
+ });
206
+ }
207
+ }
208
+ module.exports = JsonpMainTemplatePlugin;
@@ -2,52 +2,57 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var path = require("path");
6
- var async = require("async");
5
+ "use strict";
7
6
 
8
- function LibManifestPlugin(options) {
9
- this.options = options;
7
+ const path = require("path");
8
+ const asyncLib = require("async");
9
+
10
+ class LibManifestPlugin {
11
+ constructor(options) {
12
+ this.options = options;
13
+ }
14
+
15
+ apply(compiler) {
16
+ compiler.plugin("emit", (compilation, callback) => {
17
+ asyncLib.forEach(compilation.chunks, (chunk, callback) => {
18
+ if(!chunk.isInitial()) {
19
+ callback();
20
+ return;
21
+ }
22
+ const targetPath = compilation.getPath(this.options.path, {
23
+ hash: compilation.hash,
24
+ chunk
25
+ });
26
+ const name = this.options.name && compilation.getPath(this.options.name, {
27
+ hash: compilation.hash,
28
+ chunk
29
+ });
30
+ const manifest = {
31
+ name,
32
+ type: this.options.type,
33
+ content: chunk.modules.reduce((obj, module) => {
34
+ if(module.libIdent) {
35
+ const ident = module.libIdent({
36
+ context: this.options.context || compiler.options.context
37
+ });
38
+ if(ident) {
39
+ obj[ident] = {
40
+ id: module.id,
41
+ meta: module.meta,
42
+ exports: Array.isArray(module.providedExports) ? module.providedExports : undefined
43
+ };
44
+ }
45
+ }
46
+ return obj;
47
+ }, {})
48
+ };
49
+ const content = new Buffer(JSON.stringify(manifest), "utf8"); //eslint-disable-line
50
+ compiler.outputFileSystem.mkdirp(path.dirname(targetPath), err => {
51
+ if(err) return callback(err);
52
+ compiler.outputFileSystem.writeFile(targetPath, content, callback);
53
+ });
54
+ }, callback);
55
+ });
56
+ }
10
57
  }
11
58
  module.exports = LibManifestPlugin;
12
- LibManifestPlugin.prototype.apply = function(compiler) {
13
- compiler.plugin("emit", function(compilation, callback) {
14
- async.forEach(compilation.chunks, function(chunk, callback) {
15
- if(!chunk.isInitial()) {
16
- callback();
17
- return;
18
- }
19
- var targetPath = compilation.getPath(this.options.path, {
20
- hash: compilation.hash,
21
- chunk: chunk
22
- });
23
- var name = this.options.name && compilation.getPath(this.options.name, {
24
- hash: compilation.hash,
25
- chunk: chunk
26
- });
27
- var manifest = {
28
- name: name,
29
- type: this.options.type,
30
- content: chunk.modules.reduce(function(obj, module) {
31
- if(module.libIdent) {
32
- var ident = module.libIdent({
33
- context: this.options.context || compiler.options.context
34
- });
35
- if(ident) {
36
- obj[ident] = {
37
- id: module.id,
38
- meta: module.meta,
39
- exports: Array.isArray(module.providedExports) ? module.providedExports : undefined
40
- };
41
- }
42
- }
43
- return obj;
44
- }.bind(this), {})
45
- };
46
- var content = new Buffer(JSON.stringify(manifest, null, 2), "utf8"); //eslint-disable-line
47
- compiler.outputFileSystem.mkdirp(path.dirname(targetPath), function(err) {
48
- if(err) return callback(err);
49
- compiler.outputFileSystem.writeFile(targetPath, content, callback);
50
- });
51
- }.bind(this), callback);
52
- }.bind(this));
53
- };
@@ -30,8 +30,7 @@ module.exports = class MainTemplate extends Template {
30
30
  const buf = [];
31
31
  if(chunk.entryModule) {
32
32
  buf.push("// Load entry module and return exports");
33
- buf.push("return " + this.renderRequireFunctionForModule(hash, chunk, JSON.stringify(chunk.entryModule.id)) +
34
- "(" + this.requireFn + ".s = " + JSON.stringify(chunk.entryModule.id) + ");");
33
+ buf.push(`return ${this.renderRequireFunctionForModule(hash, chunk, JSON.stringify(chunk.entryModule.id))}(${this.requireFn}.s = ${JSON.stringify(chunk.entryModule.id)});`);
35
34
  }
36
35
  return this.asString(buf);
37
36
  });
@@ -58,9 +57,9 @@ module.exports = class MainTemplate extends Template {
58
57
  return this.asString([
59
58
  source,
60
59
  "// Check if module is in cache",
61
- "if(installedModules[moduleId])",
60
+ "if(installedModules[moduleId]) {",
62
61
  this.indent("return installedModules[moduleId].exports;"),
63
- "",
62
+ "}",
64
63
  "// Create a new module (and put it into the cache)",
65
64
  "var module = installedModules[moduleId] = {",
66
65
  this.indent(this.applyPluginsWaterfall("module-obj", "", chunk, hash, "moduleId")),
@@ -71,7 +70,7 @@ module.exports = class MainTemplate extends Template {
71
70
  "var threw = true;",
72
71
  "try {",
73
72
  this.indent([
74
- "modules[moduleId].call(module.exports, module, module.exports, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");",
73
+ `modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, "moduleId")});`,
75
74
  "threw = false;"
76
75
  ]),
77
76
  "} finally {",
@@ -81,7 +80,7 @@ module.exports = class MainTemplate extends Template {
81
80
  "}"
82
81
  ] : [
83
82
  "// Execute the module function",
84
- "modules[moduleId].call(module.exports, module, module.exports, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");",
83
+ `modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(hash, chunk, "moduleId")});`,
85
84
  ]),
86
85
  "",
87
86
  "// Flag the module as loaded",
@@ -103,27 +102,27 @@ module.exports = class MainTemplate extends Template {
103
102
  if(chunk.chunks.length > 0) {
104
103
  buf.push("// This file contains only the entry chunk.");
105
104
  buf.push("// The chunk loading function for additional chunks");
106
- buf.push(this.requireFn + ".e = function requireEnsure(chunkId) {");
105
+ buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
107
106
  buf.push(this.indent(this.applyPluginsWaterfall("require-ensure", "throw new Error('Not chunk loading available');", chunk, hash, "chunkId")));
108
107
  buf.push("};");
109
108
  }
110
109
  buf.push("");
111
110
  buf.push("// expose the modules object (__webpack_modules__)");
112
- buf.push(this.requireFn + ".m = modules;");
111
+ buf.push(`${this.requireFn}.m = modules;`);
113
112
 
114
113
  buf.push("");
115
114
  buf.push("// expose the module cache");
116
- buf.push(this.requireFn + ".c = installedModules;");
115
+ buf.push(`${this.requireFn}.c = installedModules;`);
117
116
 
118
117
  buf.push("");
119
118
  buf.push("// identity function for calling harmony imports with the correct context");
120
- buf.push(this.requireFn + ".i = function(value) { return value; };");
119
+ buf.push(`${this.requireFn}.i = function(value) { return value; };`);
121
120
 
122
121
  buf.push("");
123
122
  buf.push("// define getter function for harmony exports");
124
- buf.push(this.requireFn + ".d = function(exports, name, getter) {");
123
+ buf.push(`${this.requireFn}.d = function(exports, name, getter) {`);
125
124
  buf.push(this.indent([
126
- "if(!" + this.requireFn + ".o(exports, name)) {",
125
+ `if(!${this.requireFn}.o(exports, name)) {`,
127
126
  this.indent([
128
127
  "Object.defineProperty(exports, name, {",
129
128
  this.indent([
@@ -146,21 +145,21 @@ module.exports = class MainTemplate extends Template {
146
145
  "function getDefault() { return module['default']; } :",
147
146
  "function getModuleExports() { return module; };"
148
147
  ]),
149
- this.requireFn + ".d(getter, 'a', getter);",
148
+ `${this.requireFn}.d(getter, 'a', getter);`,
150
149
  "return getter;"
151
150
  ]));
152
151
  buf.push("};");
153
152
 
154
153
  buf.push("");
155
154
  buf.push("// Object.prototype.hasOwnProperty.call");
156
- buf.push(this.requireFn + ".o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };");
155
+ buf.push(`${this.requireFn}.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`);
157
156
 
158
157
  const publicPath = this.getPublicPath({
159
158
  hash: hash
160
159
  });
161
160
  buf.push("");
162
161
  buf.push("// __webpack_public_path__");
163
- buf.push(this.requireFn + ".p = " + JSON.stringify(publicPath) + ";");
162
+ buf.push(`${this.requireFn}.p = ${JSON.stringify(publicPath)};`);
164
163
  return this.asString(buf);
165
164
  });
166
165
 
@@ -173,14 +172,14 @@ module.exports = class MainTemplate extends Template {
173
172
  buf.push(this.applyPluginsWaterfall("local-vars", "", chunk, hash));
174
173
  buf.push("");
175
174
  buf.push("// The require function");
176
- buf.push("function " + this.requireFn + "(moduleId) {");
175
+ buf.push(`function ${this.requireFn}(moduleId) {`);
177
176
  buf.push(this.indent(this.applyPluginsWaterfall("require", "", chunk, hash)));
178
177
  buf.push("}");
179
178
  buf.push("");
180
179
  buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
181
180
  buf.push("");
182
181
  buf.push(this.asString(this.applyPluginsWaterfall("startup", "", chunk, hash)));
183
- let source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", "webpack/bootstrap " + hash), chunk, hash, moduleTemplate, dependencyTemplates);
182
+ let source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", `webpack/bootstrap ${hash}`), chunk, hash, moduleTemplate, dependencyTemplates);
184
183
  if(chunk.hasEntryModule()) {
185
184
  source = this.applyPluginsWaterfall("render-with-entry", source, chunk, hash);
186
185
  }
@@ -194,7 +193,7 @@ module.exports = class MainTemplate extends Template {
194
193
  }
195
194
 
196
195
  renderAddModule(hash, chunk, varModuleId, varModule) {
197
- return this.applyPluginsWaterfall("add-module", "modules[" + varModuleId + "] = " + varModule + ";", chunk, hash, varModuleId, varModule);
196
+ return this.applyPluginsWaterfall("add-module", `modules[${varModuleId}] = ${varModule};`, chunk, hash, varModuleId, varModule);
198
197
  }
199
198
 
200
199
  renderCurrentHashCode(hash, length) {