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,15 +2,21 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- function EntryModuleNotFoundError(err) {
6
- Error.call(this);
7
- this.name = "EntryModuleNotFoundError";
8
- this.message = "Entry module not found: " + err;
9
- this.details = err.details;
10
- this.error = err;
11
- Error.captureStackTrace(this, EntryModuleNotFoundError);
5
+ "use strict";
6
+
7
+ const WebpackError = require("./WebpackError");
8
+
9
+ class EntryModuleNotFoundError extends WebpackError {
10
+ constructor(err) {
11
+ super();
12
+
13
+ this.name = "EntryModuleNotFoundError";
14
+ this.message = "Entry module not found: " + err;
15
+ this.details = err.details;
16
+ this.error = err;
17
+
18
+ Error.captureStackTrace(this, this.constructor);
19
+ }
12
20
  }
13
- module.exports = EntryModuleNotFoundError;
14
21
 
15
- EntryModuleNotFoundError.prototype = Object.create(Error.prototype);
16
- EntryModuleNotFoundError.prototype.constructor = EntryModuleNotFoundError;
22
+ module.exports = EntryModuleNotFoundError;
@@ -9,10 +9,12 @@ const ParserHelpers = require("./ParserHelpers");
9
9
  const NullFactory = require("./NullFactory");
10
10
 
11
11
  const REPLACEMENTS = {
12
- __webpack_hash__: "__webpack_require__.h" // eslint-disable-line camelcase
12
+ __webpack_hash__: "__webpack_require__.h", // eslint-disable-line camelcase
13
+ __webpack_chunkname__: "__webpack_require__.cn" // eslint-disable-line camelcase
13
14
  };
14
15
  const REPLACEMENT_TYPES = {
15
- __webpack_hash__: "string" // eslint-disable-line camelcase
16
+ __webpack_hash__: "string", // eslint-disable-line camelcase
17
+ __webpack_chunkname__: "string" // eslint-disable-line camelcase
16
18
  };
17
19
 
18
20
  class ExtendedAPIPlugin {
@@ -25,6 +27,9 @@ class ExtendedAPIPlugin {
25
27
  buf.push("");
26
28
  buf.push("// __webpack_hash__");
27
29
  buf.push(`${this.requireFn}.h = ${JSON.stringify(hash)};`);
30
+ buf.push("");
31
+ buf.push("// __webpack_chunkname__");
32
+ buf.push(`${this.requireFn}.cn = ${JSON.stringify(chunk.name)};`);
28
33
  return this.asString(buf);
29
34
  });
30
35
  compilation.mainTemplate.plugin("global-hash", () => true);
@@ -35,7 +35,7 @@ class ExternalModule extends Module {
35
35
  }
36
36
 
37
37
  build(options, compilation, resolver, fs, callback) {
38
- this.builtTime = new Date().getTime();
38
+ this.builtTime = Date.now();
39
39
  callback();
40
40
  }
41
41
 
@@ -2,20 +2,21 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var ExternalModule = require("./ExternalModule");
5
+ "use strict";
6
6
 
7
- function ExternalModuleFactoryPlugin(type, externals) {
8
- this.type = type;
9
- this.externals = externals;
10
- }
11
- module.exports = ExternalModuleFactoryPlugin;
7
+ const ExternalModule = require("./ExternalModule");
8
+
9
+ class ExternalModuleFactoryPlugin {
10
+ constructor(type, externals) {
11
+ this.type = type;
12
+ this.externals = externals;
13
+ }
12
14
 
13
- ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
14
- var globalType = this.type;
15
- normalModuleFactory.plugin("factory", function(factory) {
16
- return function(data, callback) {
17
- var context = data.context;
18
- var dependency = data.dependencies[0];
15
+ apply(normalModuleFactory) {
16
+ const globalType = this.type;
17
+ normalModuleFactory.plugin("factory", factory => (data, callback) => {
18
+ const context = data.context;
19
+ const dependency = data.dependencies[0];
19
20
 
20
21
  function handleExternal(value, type, callback) {
21
22
  if(typeof type === "function") {
@@ -25,7 +26,7 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
25
26
  if(value === false) return factory(data, callback);
26
27
  if(value === true) value = dependency.request;
27
28
  if(typeof type === "undefined" && /^[a-z0-9]+ /.test(value)) {
28
- var idx = value.indexOf(" ");
29
+ const idx = value.indexOf(" ");
29
30
  type = value.substr(0, idx);
30
31
  value = value.substr(idx + 1);
31
32
  }
@@ -38,13 +39,14 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
38
39
  return handleExternal(dependency.request, callback);
39
40
  }
40
41
  } else if(Array.isArray(externals)) {
41
- var i = 0;
42
+ let i = 0;
42
43
  (function next() {
43
- var handleExternalsAndCallback = function handleExternalsAndCallback(err, module) {
44
+ let asyncFlag;
45
+ const handleExternalsAndCallback = function handleExternalsAndCallback(err, module) {
44
46
  if(err) return callback(err);
45
47
  if(!module) {
46
- if(async) {
47
- async = false;
48
+ if(asyncFlag) {
49
+ asyncFlag = false;
48
50
  return;
49
51
  }
50
52
  return next();
@@ -53,11 +55,11 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
53
55
  };
54
56
 
55
57
  do {
56
- var async = true;
58
+ asyncFlag = true;
57
59
  if(i >= externals.length) return callback();
58
60
  handleExternals(externals[i++], handleExternalsAndCallback);
59
- } while (!async); // eslint-disable-line keyword-spacing
60
- async = false;
61
+ } while (!asyncFlag); // eslint-disable-line keyword-spacing
62
+ asyncFlag = false;
61
63
  }());
62
64
  return;
63
65
  } else if(externals instanceof RegExp) {
@@ -83,6 +85,7 @@ ExternalModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
83
85
  if(!module) return handleExternal(false, callback);
84
86
  return callback(null, module);
85
87
  }));
86
- }.bind(this);
87
- }.bind(this));
88
- };
88
+ });
89
+ }
90
+ }
91
+ module.exports = ExternalModuleFactoryPlugin;
@@ -2,92 +2,80 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- function FlagDependencyUsagePlugin() {
5
+ "use strict";
6
6
 
7
- }
8
- module.exports = FlagDependencyUsagePlugin;
7
+ class FlagDependencyUsagePlugin {
8
+ apply(compiler) {
9
+ compiler.plugin("compilation", compilation => {
10
+ compilation.plugin("optimize-modules-advanced", modules => {
9
11
 
10
- FlagDependencyUsagePlugin.prototype.apply = function(compiler) {
11
- compiler.plugin("compilation", function(compilation) {
12
- compilation.plugin("optimize-modules-advanced", function(modules) {
12
+ modules.forEach(module => module.used = false);
13
13
 
14
- modules.forEach(function(module) {
15
- module.used = false;
16
- });
14
+ const queue = [];
15
+ compilation.chunks.forEach(chunk => {
16
+ if(chunk.entryModule) {
17
+ processModule(chunk.entryModule, true);
18
+ }
19
+ });
17
20
 
18
- var queue = [];
19
- compilation.chunks.forEach(function(chunk) {
20
- if(chunk.entryModule) {
21
- processModule(chunk.entryModule, true);
21
+ while(queue.length) {
22
+ const queueItem = queue.pop();
23
+ processDependenciesBlock(queueItem[0], queueItem[1]);
22
24
  }
23
- });
24
-
25
- while(queue.length) {
26
- var queueItem = queue.pop();
27
- processDependenciesBlock(queueItem[0], queueItem[1]);
28
- }
29
25
 
30
- function processModule(module, usedExports) {
31
- module.used = true;
32
- if(module.usedExports === true)
33
- return;
34
- else if(usedExports === true)
35
- module.usedExports = true;
36
- else if(Array.isArray(usedExports)) {
37
- var old = module.usedExports ? module.usedExports.length : -1;
38
- module.usedExports = addToSet(module.usedExports || [], usedExports);
39
- if(module.usedExports.length === old)
26
+ function processModule(module, usedExports) {
27
+ module.used = true;
28
+ if(module.usedExports === true)
40
29
  return;
41
- } else if(Array.isArray(module.usedExports))
42
- return;
43
- else
44
- module.usedExports = false;
45
-
46
- queue.push([module, module.usedExports]);
47
- }
30
+ else if(usedExports === true)
31
+ module.usedExports = true;
32
+ else if(Array.isArray(usedExports)) {
33
+ var old = module.usedExports ? module.usedExports.length : -1;
34
+ module.usedExports = addToSet(module.usedExports || [], usedExports);
35
+ if(module.usedExports.length === old)
36
+ return;
37
+ } else if(Array.isArray(module.usedExports))
38
+ return;
39
+ else
40
+ module.usedExports = false;
48
41
 
49
- function processDependenciesBlock(depBlock, usedExports) {
50
- depBlock.dependencies.forEach(function(dep) {
51
- processDependency(dep, usedExports);
52
- });
53
- depBlock.variables.forEach(function(variable) {
54
- variable.dependencies.forEach(function(dep) {
55
- processDependency(dep, usedExports);
56
- });
57
- });
58
- depBlock.blocks.forEach(function(block) {
59
- queue.push([block, usedExports]);
60
- });
61
- }
42
+ queue.push([module, module.usedExports]);
43
+ }
62
44
 
63
- function processDependency(dep, usedExports) {
64
- var reference = dep.getReference && dep.getReference();
65
- if(!reference) return;
66
- var module = reference.module;
67
- var importedNames = reference.importedNames;
68
- var oldUsed = module.used;
69
- var oldUsedExports = module.usedExports;
70
- if(!oldUsed || (importedNames && (!oldUsedExports || !isSubset(oldUsedExports, importedNames)))) {
71
- processModule(module, importedNames);
45
+ function processDependenciesBlock(depBlock, usedExports) {
46
+ depBlock.dependencies.forEach(dep => processDependency(dep));
47
+ depBlock.variables.forEach(variable => variable.dependencies.forEach(dep => processDependency(dep)));
48
+ depBlock.blocks.forEach(block => queue.push([block, usedExports]));
72
49
  }
73
- }
74
50
 
75
- });
51
+ function processDependency(dep) {
52
+ const reference = dep.getReference && dep.getReference();
53
+ if(!reference) return;
54
+ const module = reference.module;
55
+ const importedNames = reference.importedNames;
56
+ const oldUsed = module.used;
57
+ const oldUsedExports = module.usedExports;
58
+ if(!oldUsed || (importedNames && (!oldUsedExports || !isSubset(oldUsedExports, importedNames)))) {
59
+ processModule(module, importedNames);
60
+ }
61
+ }
76
62
 
77
- function addToSet(a, b) {
78
- b.forEach(function(item) {
79
- if(a.indexOf(item) < 0)
80
- a.push(item);
81
63
  });
82
- return a;
83
- }
84
64
 
85
- function isSubset(biggerSet, subset) {
86
- if(biggerSet === true) return true;
87
- if(subset === true) return false;
88
- return subset.every(function(item) {
89
- return biggerSet.indexOf(item) >= 0;
90
- });
91
- }
92
- });
93
- };
65
+ function addToSet(a, b) {
66
+ b.forEach(item => {
67
+ if(a.indexOf(item) < 0)
68
+ a.push(item);
69
+ });
70
+ return a;
71
+ }
72
+
73
+ function isSubset(biggerSet, subset) {
74
+ if(biggerSet === true) return true;
75
+ if(subset === true) return false;
76
+ return subset.every(item => biggerSet.indexOf(item) >= 0);
77
+ }
78
+ });
79
+ }
80
+ }
81
+ module.exports = FlagDependencyUsagePlugin;
@@ -8,7 +8,7 @@ module.exports = function() {
8
8
  var hotApplyOnUpdate = true;
9
9
  var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
10
10
  var hotCurrentModuleData = {};
11
- var hotMainModule = true; // eslint-disable-line no-unused-vars
11
+ var hotCurrentChildModule; // eslint-disable-line no-unused-vars
12
12
  var hotCurrentParents = []; // eslint-disable-line no-unused-vars
13
13
  var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars
14
14
 
@@ -20,14 +20,16 @@ module.exports = function() {
20
20
  if(installedModules[request]) {
21
21
  if(installedModules[request].parents.indexOf(moduleId) < 0)
22
22
  installedModules[request].parents.push(moduleId);
23
- } else hotCurrentParents = [moduleId];
23
+ } else {
24
+ hotCurrentParents = [moduleId];
25
+ hotCurrentChildModule = request;
26
+ }
24
27
  if(me.children.indexOf(request) < 0)
25
28
  me.children.push(request);
26
29
  } else {
27
30
  console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
28
31
  hotCurrentParents = [];
29
32
  }
30
- hotMainModule = false;
31
33
  return $require$(request);
32
34
  };
33
35
  var ObjectFactory = function ObjectFactory(name) {
@@ -43,34 +45,31 @@ module.exports = function() {
43
45
  };
44
46
  };
45
47
  for(var name in $require$) {
46
- if(Object.prototype.hasOwnProperty.call($require$, name)) {
48
+ if(Object.prototype.hasOwnProperty.call($require$, name) && name !== "e") {
47
49
  Object.defineProperty(fn, name, ObjectFactory(name));
48
50
  }
49
51
  }
50
- Object.defineProperty(fn, "e", {
51
- enumerable: true,
52
- value: function(chunkId) {
53
- if(hotStatus === "ready")
54
- hotSetStatus("prepare");
55
- hotChunksLoading++;
56
- return $require$.e(chunkId).then(finishChunkLoading, function(err) {
57
- finishChunkLoading();
58
- throw err;
59
- });
52
+ fn.e = function(chunkId) {
53
+ if(hotStatus === "ready")
54
+ hotSetStatus("prepare");
55
+ hotChunksLoading++;
56
+ return $require$.e(chunkId).then(finishChunkLoading, function(err) {
57
+ finishChunkLoading();
58
+ throw err;
59
+ });
60
60
 
61
- function finishChunkLoading() {
62
- hotChunksLoading--;
63
- if(hotStatus === "prepare") {
64
- if(!hotWaitingFilesMap[chunkId]) {
65
- hotEnsureUpdateChunk(chunkId);
66
- }
67
- if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
68
- hotUpdateDownloaded();
69
- }
61
+ function finishChunkLoading() {
62
+ hotChunksLoading--;
63
+ if(hotStatus === "prepare") {
64
+ if(!hotWaitingFilesMap[chunkId]) {
65
+ hotEnsureUpdateChunk(chunkId);
66
+ }
67
+ if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
68
+ hotUpdateDownloaded();
70
69
  }
71
70
  }
72
71
  }
73
- });
72
+ };
74
73
  return fn;
75
74
  }
76
75
 
@@ -82,7 +81,7 @@ module.exports = function() {
82
81
  _selfAccepted: false,
83
82
  _selfDeclined: false,
84
83
  _disposeHandlers: [],
85
- _main: hotMainModule,
84
+ _main: hotCurrentChildModule !== moduleId,
86
85
 
87
86
  // Module API
88
87
  active: true,
@@ -135,7 +134,7 @@ module.exports = function() {
135
134
  //inherit from previous dispose call
136
135
  data: hotCurrentModuleData[moduleId]
137
136
  };
138
- hotMainModule = true;
137
+ hotCurrentChildModule = undefined;
139
138
  return hot;
140
139
  }
141
140
 
@@ -173,7 +172,6 @@ module.exports = function() {
173
172
  hotSetStatus("idle");
174
173
  return null;
175
174
  }
176
-
177
175
  hotRequestedFilesMap = {};
178
176
  hotWaitingFilesMap = {};
179
177
  hotAvailableFilesMap = update.c;
@@ -109,10 +109,8 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
109
109
  c: {}
110
110
  };
111
111
  Object.keys(records.chunkHashs).forEach(function(chunkId) {
112
- chunkId = +chunkId;
113
- var currentChunk = this.chunks.filter(function(chunk) {
114
- return chunk.id === chunkId;
115
- })[0];
112
+ chunkId = isNaN(+chunkId) ? chunkId : +chunkId;
113
+ var currentChunk = this.chunks.find(chunk => chunk.id === chunkId);
116
114
  if(currentChunk) {
117
115
  var newModules = currentChunk.modules.filter(function(module) {
118
116
  return module.hotUpdate;
@@ -171,7 +169,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
171
169
  hotInitCode
172
170
  .replace(/\$require\$/g, this.requireFn)
173
171
  .replace(/\$hash\$/g, JSON.stringify(hash))
174
- .replace(/\/\*foreachInstalledChunks\*\//g, chunk.chunks.length > 0 ? "for(var chunkId in installedChunks)" : "var chunkId = " + chunk.id + ";")
172
+ .replace(/\/\*foreachInstalledChunks\*\//g, chunk.chunks.length > 0 ? "for(var chunkId in installedChunks)" : "var chunkId = " + JSON.stringify(chunk.id) + ";")
175
173
  ]);
176
174
  });
177
175
 
@@ -8,29 +8,60 @@ class IgnorePlugin {
8
8
  constructor(resourceRegExp, contextRegExp) {
9
9
  this.resourceRegExp = resourceRegExp;
10
10
  this.contextRegExp = contextRegExp;
11
+
12
+ this.checkIgnore = this.checkIgnore.bind(this);
13
+ }
14
+
15
+ /*
16
+ * Only returns true if a "resourceRegExp" exists
17
+ * and the resource given matches the regexp.
18
+ */
19
+ checkResource(resource) {
20
+ if(!this.resourceRegExp) {
21
+ return false;
22
+ }
23
+ return this.resourceRegExp.test(resource);
24
+ }
25
+
26
+ /*
27
+ * Returns true if contextRegExp does not exist
28
+ * or if context matches the given regexp.
29
+ */
30
+ checkContext(context) {
31
+ if(!this.contextRegExp) {
32
+ return true;
33
+ }
34
+ return this.contextRegExp.test(context);
35
+ }
36
+
37
+ /*
38
+ * Returns true if result should be ignored.
39
+ * false if it shouldn't.
40
+ *
41
+ * Not that if "contextRegExp" is given, both the "resourceRegExp"
42
+ * and "contextRegExp" have to match.
43
+ */
44
+ checkResult(result) {
45
+ if(!result) {
46
+ return true;
47
+ }
48
+ return this.checkResource(result.request) && this.checkContext(result.context);
49
+ }
50
+
51
+ checkIgnore(result, callback) {
52
+ // check if result is ignored
53
+ if(this.checkResult(result)) {
54
+ return callback();
55
+ }
56
+ return callback(null, result);
11
57
  }
12
58
 
13
59
  apply(compiler) {
14
- const resourceRegExp = this.resourceRegExp;
15
- const contextRegExp = this.contextRegExp;
16
60
  compiler.plugin("normal-module-factory", (nmf) => {
17
- nmf.plugin("before-resolve", (result, callback) => {
18
- if(!result) return callback();
19
- if(resourceRegExp.test(result.request) &&
20
- (!contextRegExp || contextRegExp.test(result.context))) {
21
- return callback();
22
- }
23
- return callback(null, result);
24
- });
61
+ nmf.plugin("before-resolve", this.checkIgnore);
25
62
  });
26
63
  compiler.plugin("context-module-factory", (cmf) => {
27
- cmf.plugin("before-resolve", (result, callback) => {
28
- if(!result) return callback();
29
- if(resourceRegExp.test(result.request)) {
30
- return callback();
31
- }
32
- return callback(null, result);
33
- });
64
+ cmf.plugin("before-resolve", this.checkIgnore);
34
65
  });
35
66
  }
36
67
  }
@@ -2,30 +2,30 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var ConcatSource = require("webpack-sources").ConcatSource;
5
+ "use strict";
6
6
 
7
- function JsonpChunkTemplatePlugin() {}
8
- module.exports = JsonpChunkTemplatePlugin;
7
+ const ConcatSource = require("webpack-sources").ConcatSource;
9
8
 
10
- JsonpChunkTemplatePlugin.prototype.apply = function(chunkTemplate) {
11
- chunkTemplate.plugin("render", function(modules, chunk) {
12
- var jsonpFunction = this.outputOptions.jsonpFunction;
13
- var source = new ConcatSource();
14
- source.add(jsonpFunction + "(" + JSON.stringify(chunk.ids) + ",");
15
- source.add(modules);
16
- var entries = [chunk.entryModule].filter(Boolean).map(function(m) {
17
- return m.id;
9
+ class JsonpChunkTemplatePlugin {
10
+ apply(chunkTemplate) {
11
+ chunkTemplate.plugin("render", function(modules, chunk) {
12
+ const jsonpFunction = this.outputOptions.jsonpFunction;
13
+ const source = new ConcatSource();
14
+ source.add(`${jsonpFunction}(${JSON.stringify(chunk.ids)},`);
15
+ source.add(modules);
16
+ const entries = [chunk.entryModule].filter(Boolean).map(m => m.id);
17
+ if(entries.length > 0) {
18
+ source.add(`,${JSON.stringify(entries)}`);
19
+ }
20
+ source.add(")");
21
+ return source;
22
+ });
23
+ chunkTemplate.plugin("hash", function(hash) {
24
+ hash.update("JsonpChunkTemplatePlugin");
25
+ hash.update("3");
26
+ hash.update(`${this.outputOptions.jsonpFunction}`);
27
+ hash.update(`${this.outputOptions.library}`);
18
28
  });
19
- if(entries.length > 0) {
20
- source.add("," + JSON.stringify(entries));
21
- }
22
- source.add(")");
23
- return source;
24
- });
25
- chunkTemplate.plugin("hash", function(hash) {
26
- hash.update("JsonpChunkTemplatePlugin");
27
- hash.update("3");
28
- hash.update(this.outputOptions.jsonpFunction + "");
29
- hash.update(this.outputOptions.library + "");
30
- });
31
- };
29
+ }
30
+ }
31
+ module.exports = JsonpChunkTemplatePlugin;