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
@@ -157,9 +157,9 @@ class ProgressPlugin {
157
157
  state = state.replace(/^\d+\/\d+\s+/, "");
158
158
  if(percentage === 0) {
159
159
  lastState = null;
160
- lastStateTime = +new Date();
160
+ lastStateTime = Date.now();
161
161
  } else if(state !== lastState || percentage === 1) {
162
- const now = +new Date();
162
+ const now = Date.now();
163
163
  if(lastState) {
164
164
  const stateMsg = `${now - lastStateTime}ms ${lastState}`;
165
165
  goToLineStart(stateMsg);
package/lib/RawModule.js CHANGED
@@ -36,7 +36,7 @@ module.exports = class RawModule extends Module {
36
36
  }
37
37
 
38
38
  build(options, compilations, resolver, fs, callback) {
39
- this.builtTime = new Date().getTime();
39
+ this.builtTime = Date.now();
40
40
  callback();
41
41
  }
42
42
 
@@ -4,14 +4,10 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- function makeRelative(compiler, identifier) {
8
- const context = compiler.context;
9
- return identifier.split("|").map(str => str.split("!").map(str => path.relative(context, str)).join("!")).join("|");
10
- }
11
-
12
- const path = require("path");
7
+ const identifierUtils = require("./util/identifier");
13
8
 
14
9
  class RecordIdsPlugin {
10
+
15
11
  apply(compiler) {
16
12
  compiler.plugin("compilation", compilation => {
17
13
  compilation.plugin("record-modules", (modules, records) => {
@@ -19,7 +15,7 @@ class RecordIdsPlugin {
19
15
  if(!records.modules.byIdentifier) records.modules.byIdentifier = {};
20
16
  if(!records.modules.usedIds) records.modules.usedIds = {};
21
17
  modules.forEach(function(module) {
22
- if(!module.portableId) module.portableId = makeRelative(compiler, module.identifier());
18
+ if(!module.portableId) module.portableId = identifierUtils.makePathsRelative(compiler.context, module.identifier());
23
19
  const identifier = module.portableId;
24
20
  records.modules.byIdentifier[identifier] = module.id;
25
21
  records.modules.usedIds[module.id] = module.id;
@@ -31,7 +27,7 @@ class RecordIdsPlugin {
31
27
  const usedIds = {};
32
28
  modules.forEach(function(module) {
33
29
  if(module.id !== null) return;
34
- if(!module.portableId) module.portableId = makeRelative(compiler, module.identifier());
30
+ if(!module.portableId) module.portableId = identifierUtils.makePathsRelative(compiler.context, module.identifier());
35
31
  const identifier = module.portableId;
36
32
  const id = records.modules.byIdentifier[identifier];
37
33
  if(id === undefined) return;
@@ -55,7 +51,7 @@ class RecordIdsPlugin {
55
51
  block = block.parent;
56
52
  }
57
53
  if(!block.identifier) return null;
58
- ident.unshift(makeRelative(compiler, block.identifier()));
54
+ ident.unshift(identifierUtils.makePathsRelative(compiler.context, block.identifier()));
59
55
  return ident.join(":");
60
56
  }
61
57
  compilation.plugin("record-chunks", (chunks, records) => {
@@ -26,7 +26,7 @@ class SetVarMainTemplatePlugin {
26
26
  return new ConcatSource(prefix, source);
27
27
  }
28
28
  });
29
- mainTemplate.plugin("global-hash-paths", function(paths) {
29
+ mainTemplate.plugin("global-hash-paths", (paths) => {
30
30
  if(this.varExpression) paths.push(this.varExpression);
31
31
  return paths;
32
32
  });
@@ -2,169 +2,165 @@
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 RequestShortener = require("./RequestShortener");
7
- var ConcatSource = require("webpack-sources").ConcatSource;
8
- var RawSource = require("webpack-sources").RawSource;
9
- var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
10
- var SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
5
+ "use strict";
11
6
 
12
- function SourceMapDevToolPlugin(options) {
13
- if(arguments.length > 1)
14
- throw new Error("SourceMapDevToolPlugin only takes one argument (pass an options object)");
15
- if(typeof options === "string") {
16
- options = {
17
- sourceMapFilename: options
18
- };
7
+ const path = require("path");
8
+ const RequestShortener = require("./RequestShortener");
9
+ const ConcatSource = require("webpack-sources").ConcatSource;
10
+ const RawSource = require("webpack-sources").RawSource;
11
+ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
12
+ const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
13
+
14
+ const basename = (name) => {
15
+ if(name.indexOf("/") < 0) return name;
16
+ return name.substr(name.lastIndexOf("/") + 1);
17
+ };
18
+
19
+ class SourceMapDevToolPlugin {
20
+ constructor(options) {
21
+ if(arguments.length > 1)
22
+ throw new Error("SourceMapDevToolPlugin only takes one argument (pass an options object)");
23
+ // TODO: remove in webpack 3
24
+ if(typeof options === "string") {
25
+ options = {
26
+ sourceMapFilename: options
27
+ };
28
+ }
29
+ if(!options) options = {};
30
+ this.sourceMapFilename = options.filename;
31
+ this.sourceMappingURLComment = options.append === false ? false : options.append || "\n//# sourceMappingURL=[url]";
32
+ this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resourcePath]";
33
+ this.fallbackModuleFilenameTemplate = options.fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
34
+ this.options = options;
19
35
  }
20
- if(!options) options = {};
21
- this.sourceMapFilename = options.filename;
22
- this.sourceMappingURLComment = options.append === false ? false : options.append || "\n//# sourceMappingURL=[url]";
23
- this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resourcePath]";
24
- this.fallbackModuleFilenameTemplate = options.fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
25
- this.options = options;
26
- }
27
- module.exports = SourceMapDevToolPlugin;
28
- SourceMapDevToolPlugin.prototype.apply = function(compiler) {
29
- var sourceMapFilename = this.sourceMapFilename;
30
- var sourceMappingURLComment = this.sourceMappingURLComment;
31
- var moduleFilenameTemplate = this.moduleFilenameTemplate;
32
- var fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
33
- var requestShortener = new RequestShortener(compiler.context);
34
- var options = this.options;
35
- options.test = options.test || /\.(js|css)($|\?)/i;
36
- compiler.plugin("compilation", function(compilation) {
37
- new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
38
- compilation.plugin("after-optimize-chunk-assets", function(chunks) {
39
- var allModules = [];
40
- var allModuleFilenames = [];
41
- var tasks = [];
42
- chunks.forEach(function(chunk) {
43
- chunk.files.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options)).map(function(file) {
44
- var asset = this.assets[file];
45
- if(asset.__SourceMapDevToolData) {
46
- var data = asset.__SourceMapDevToolData;
47
- for(var cachedFile in data) {
48
- this.assets[cachedFile] = data[cachedFile];
49
- if(cachedFile !== file)
50
- chunk.files.push(cachedFile);
36
+
37
+ apply(compiler) {
38
+ const sourceMapFilename = this.sourceMapFilename;
39
+ const sourceMappingURLComment = this.sourceMappingURLComment;
40
+ const moduleFilenameTemplate = this.moduleFilenameTemplate;
41
+ const fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
42
+ const requestShortener = new RequestShortener(compiler.context);
43
+ const options = this.options;
44
+ options.test = options.test || /\.(js|css)($|\?)/i;
45
+ compiler.plugin("compilation", compilation => {
46
+ new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
47
+ compilation.plugin("after-optimize-chunk-assets", function(chunks) {
48
+ let allModules = [];
49
+ let allModuleFilenames = [];
50
+ const tasks = [];
51
+ chunks.forEach(function(chunk) {
52
+ chunk.files.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options)).map(function(file) {
53
+ const asset = compilation.assets[file];
54
+ if(asset.__SourceMapDevToolFile === file && asset.__SourceMapDevToolData) {
55
+ const data = asset.__SourceMapDevToolData;
56
+ for(const cachedFile in data) {
57
+ compilation.assets[cachedFile] = data[cachedFile];
58
+ if(cachedFile !== file)
59
+ chunk.files.push(cachedFile);
60
+ }
61
+ return;
51
62
  }
52
- return;
53
- }
54
- var source;
55
- var sourceMap;
56
- if(asset.sourceAndMap) {
57
- var sourceAndMap = asset.sourceAndMap(options);
58
- sourceMap = sourceAndMap.map;
59
- source = sourceAndMap.source;
63
+ let source, sourceMap;
64
+ if(asset.sourceAndMap) {
65
+ const sourceAndMap = asset.sourceAndMap(options);
66
+ sourceMap = sourceAndMap.map;
67
+ source = sourceAndMap.source;
68
+ } else {
69
+ sourceMap = asset.map(options);
70
+ source = asset.source();
71
+ }
72
+ if(sourceMap) {
73
+ return {
74
+ chunk,
75
+ file,
76
+ asset,
77
+ source,
78
+ sourceMap
79
+ };
80
+ }
81
+ }).filter(Boolean).map(task => {
82
+ const modules = task.sourceMap.sources.map(source => {
83
+ const module = compilation.findModule(source);
84
+ return module || source;
85
+ });
86
+ const moduleFilenames = modules.map(module => ModuleFilenameHelpers.createFilename(module, moduleFilenameTemplate, requestShortener));
87
+ task.modules = modules;
88
+ task.moduleFilenames = moduleFilenames;
89
+ return task;
90
+ }).forEach(task => {
91
+ allModules = allModules.concat(task.modules);
92
+ allModuleFilenames = allModuleFilenames.concat(task.moduleFilenames);
93
+ tasks.push(task);
94
+ });
95
+ });
96
+ allModuleFilenames = ModuleFilenameHelpers.replaceDuplicates(allModuleFilenames, (filename, i) => ModuleFilenameHelpers.createFilename(allModules[i], fallbackModuleFilenameTemplate, requestShortener), (ai, bi) => {
97
+ let a = allModules[ai];
98
+ let b = allModules[bi];
99
+ a = !a ? "" : typeof a === "string" ? a : a.identifier();
100
+ b = !b ? "" : typeof b === "string" ? b : b.identifier();
101
+ return a.length - b.length;
102
+ });
103
+ allModuleFilenames = ModuleFilenameHelpers.replaceDuplicates(allModuleFilenames, (filename, i, n) => {
104
+ for(let j = 0; j < n; j++)
105
+ filename += "*";
106
+ return filename;
107
+ });
108
+ tasks.forEach(task => {
109
+ task.moduleFilenames = allModuleFilenames.slice(0, task.moduleFilenames.length);
110
+ allModuleFilenames = allModuleFilenames.slice(task.moduleFilenames.length);
111
+ });
112
+ tasks.forEach(function(task) {
113
+ const chunk = task.chunk;
114
+ const file = task.file;
115
+ const asset = task.asset;
116
+ const sourceMap = task.sourceMap;
117
+ const source = task.source;
118
+ const moduleFilenames = task.moduleFilenames;
119
+ const modules = task.modules;
120
+ sourceMap.sources = moduleFilenames;
121
+ if(sourceMap.sourcesContent && !options.noSources) {
122
+ sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}`);
60
123
  } else {
61
- sourceMap = asset.map(options);
62
- source = asset.source();
124
+ sourceMap.sourcesContent = undefined;
63
125
  }
64
- if(sourceMap) {
65
- return {
66
- chunk: chunk,
67
- file: file,
68
- asset: asset,
69
- source: source,
70
- sourceMap: sourceMap
71
- };
72
- }
73
- }, this).filter(Boolean).map(function(task) {
74
- var modules = task.sourceMap.sources.map(function(source) {
75
- var module = compilation.findModule(source);
76
- return module || source;
77
- });
78
- var moduleFilenames = modules.map(function(module) {
79
- return ModuleFilenameHelpers.createFilename(module, moduleFilenameTemplate, requestShortener);
80
- });
81
- task.modules = modules;
82
- task.moduleFilenames = moduleFilenames;
83
- return task;
84
- }, this).forEach(function(task) {
85
- allModules = allModules.concat(task.modules);
86
- allModuleFilenames = allModuleFilenames.concat(task.moduleFilenames);
87
- tasks.push(task);
88
- }, this);
89
- }, this);
90
- allModuleFilenames = ModuleFilenameHelpers.replaceDuplicates(allModuleFilenames, function(filename, i) {
91
- return ModuleFilenameHelpers.createFilename(allModules[i], fallbackModuleFilenameTemplate, requestShortener);
92
- }, function(ai, bi) {
93
- var a = allModules[ai];
94
- var b = allModules[bi];
95
- a = !a ? "" : typeof a === "string" ? a : a.identifier();
96
- b = !b ? "" : typeof b === "string" ? b : b.identifier();
97
- return a.length - b.length;
98
- });
99
- allModuleFilenames = ModuleFilenameHelpers.replaceDuplicates(allModuleFilenames, function(filename, i, n) {
100
- for(var j = 0; j < n; j++)
101
- filename += "*";
102
- return filename;
103
- });
104
- tasks.forEach(function(task) {
105
- task.moduleFilenames = allModuleFilenames.slice(0, task.moduleFilenames.length);
106
- allModuleFilenames = allModuleFilenames.slice(task.moduleFilenames.length);
107
- }, this);
108
- tasks.forEach(function(task) {
109
- var chunk = task.chunk;
110
- var file = task.file;
111
- var asset = task.asset;
112
- var sourceMap = task.sourceMap;
113
- var source = task.source;
114
- var moduleFilenames = task.moduleFilenames;
115
- var modules = task.modules;
116
- sourceMap.sources = moduleFilenames;
117
- if(sourceMap.sourcesContent && !options.noSources) {
118
- sourceMap.sourcesContent = sourceMap.sourcesContent.map(function(content, i) {
119
- return content + "\n\n\n" + ModuleFilenameHelpers.createFooter(modules[i], requestShortener);
120
- });
121
- } else {
122
- sourceMap.sourcesContent = undefined;
123
- }
124
- sourceMap.sourceRoot = options.sourceRoot || "";
125
- sourceMap.file = file;
126
- asset.__SourceMapDevToolData = {};
127
- var currentSourceMappingURLComment = sourceMappingURLComment;
128
- if(currentSourceMappingURLComment !== false && /\.css($|\?)/i.test(file)) {
129
- currentSourceMappingURLComment = currentSourceMappingURLComment.replace(/^\n\/\/(.*)$/, "\n/*$1*/");
130
- }
131
- if(sourceMapFilename) {
132
- var filename = file,
133
- query = "";
134
- var idx = filename.indexOf("?");
135
- if(idx >= 0) {
136
- query = filename.substr(idx);
137
- filename = filename.substr(0, idx);
126
+ sourceMap.sourceRoot = options.sourceRoot || "";
127
+ sourceMap.file = file;
128
+ asset.__SourceMapDevToolFile = file;
129
+ asset.__SourceMapDevToolData = {};
130
+ let currentSourceMappingURLComment = sourceMappingURLComment;
131
+ if(currentSourceMappingURLComment !== false && /\.css($|\?)/i.test(file)) {
132
+ currentSourceMappingURLComment = currentSourceMappingURLComment.replace(/^\n\/\/(.*)$/, "\n/*$1*/");
138
133
  }
139
- var sourceMapFile = this.getPath(sourceMapFilename, {
140
- chunk: chunk,
141
- filename: filename,
142
- query: query,
143
- basename: basename(filename)
144
- });
145
- var sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
146
- if(currentSourceMappingURLComment !== false) {
147
- asset.__SourceMapDevToolData[file] = this.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
134
+ if(sourceMapFilename) {
135
+ let filename = file;
136
+ let query = "";
137
+ const idx = filename.indexOf("?");
138
+ if(idx >= 0) {
139
+ query = filename.substr(idx);
140
+ filename = filename.substr(0, idx);
141
+ }
142
+ const sourceMapFile = compilation.getPath(sourceMapFilename, {
143
+ chunk,
144
+ filename,
145
+ query,
146
+ basename: basename(filename)
147
+ });
148
+ const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
149
+ if(currentSourceMappingURLComment !== false) {
150
+ asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
151
+ }
152
+ asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap));
153
+ chunk.files.push(sourceMapFile);
154
+ } else {
155
+ asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
156
+ .replace(/\[map\]/g, () => JSON.stringify(sourceMap))
157
+ .replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(JSON.stringify(sourceMap), "utf-8").toString("base64")}`) // eslint-disable-line
158
+ );
148
159
  }
149
- asset.__SourceMapDevToolData[sourceMapFile] = this.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap));
150
- chunk.files.push(sourceMapFile);
151
- } else {
152
- asset.__SourceMapDevToolData[file] = this.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
153
- .replace(/\[map\]/g, function() {
154
- return JSON.stringify(sourceMap);
155
- })
156
- .replace(/\[url\]/g, function() {
157
- return "data:application/json;charset=utf-8;base64," +
158
- new Buffer(JSON.stringify(sourceMap), "utf8").toString("base64"); //eslint-disable-line
159
- })
160
- );
161
- }
162
- }, this);
160
+ });
161
+ });
163
162
  });
164
- });
165
- };
166
-
167
- function basename(name) {
168
- if(name.indexOf("/") < 0) return name;
169
- return name.substr(name.lastIndexOf("/") + 1);
163
+ }
170
164
  }
165
+
166
+ module.exports = SourceMapDevToolPlugin;
package/lib/Stats.js CHANGED
@@ -16,6 +16,34 @@ class Stats {
16
16
  this.hash = compilation.hash;
17
17
  }
18
18
 
19
+ static filterWarnings(warnings, warningsFilter) {
20
+ // we dont have anything to filter so all warnings can be shown
21
+ if(!warningsFilter) {
22
+ return warnings;
23
+ }
24
+
25
+ // create a chain of filters
26
+ // if they return "true" a warning should be surpressed
27
+ const normalizedWarningsFilters = [].concat(warningsFilter).map(filter => {
28
+ if(typeof filter === "string") {
29
+ return warning => warning.indexOf(filter) > -1;
30
+ }
31
+
32
+ if(filter instanceof RegExp) {
33
+ return warning => filter.test(warning);
34
+ }
35
+
36
+ if(typeof filter === "function") {
37
+ return filter;
38
+ }
39
+
40
+ throw new Error(`Can only filter warnings with Strings or RegExps. (Given: ${filter})`);
41
+ });
42
+ return warnings.filter(warning => {
43
+ return !normalizedWarningsFilters.some(check => check(warning));
44
+ });
45
+ }
46
+
19
47
  hasWarnings() {
20
48
  return this.compilation.warnings.length > 0;
21
49
  }
@@ -67,9 +95,11 @@ class Stats {
67
95
  const showProvidedExports = optionOrFallback(options.providedExports, !forToString);
68
96
  const showChildren = optionOrFallback(options.children, true);
69
97
  const showSource = optionOrFallback(options.source, !forToString);
98
+ const showModuleTrace = optionOrFallback(options.moduleTrace, true);
70
99
  const showErrors = optionOrFallback(options.errors, true);
71
100
  const showErrorDetails = optionOrFallback(options.errorDetails, !forToString);
72
101
  const showWarnings = optionOrFallback(options.warnings, true);
102
+ const warningsFilter = optionOrFallback(options.warningsFilter, null);
73
103
  const showPublicPath = optionOrFallback(options.publicPath, !forToString);
74
104
  const excludeModules = [].concat(optionOrFallback(options.exclude, [])).map(str => {
75
105
  if(typeof str !== "string") return str;
@@ -135,7 +165,7 @@ class Stats {
135
165
  text += e.message;
136
166
  if(showErrorDetails && e.details) text += `\n${e.details}`;
137
167
  if(showErrorDetails && e.missing) text += e.missing.map(item => `\n[${item}]`).join("");
138
- if(e.dependencies && e.origin) {
168
+ if(showModuleTrace && e.dependencies && e.origin) {
139
169
  text += `\n @ ${e.origin.readableIdentifier(requestShortener)}`;
140
170
  e.dependencies.forEach(dep => {
141
171
  if(!dep.loc) return;
@@ -155,7 +185,7 @@ class Stats {
155
185
 
156
186
  const obj = {
157
187
  errors: compilation.errors.map(formatError),
158
- warnings: compilation.warnings.map(formatError)
188
+ warnings: Stats.filterWarnings(compilation.warnings.map(formatError), warningsFilter)
159
189
  };
160
190
 
161
191
  //We just hint other renderers since actually omitting
@@ -270,9 +300,7 @@ class Stats {
270
300
  type: reason.dependency.type,
271
301
  userRequest: reason.dependency.userRequest
272
302
  };
273
- const dep = reason.dependency;
274
- if(dep.templateModules) obj.templateModules = dep.templateModules.map(module => module.id);
275
- const locInfo = formatLocation(dep.loc);
303
+ const locInfo = formatLocation(reason.dependency.loc);
276
304
  if(locInfo) obj.loc = locInfo;
277
305
  return obj;
278
306
  }).sort((a, b) => a.moduleId - b.moduleId);
@@ -614,7 +642,6 @@ class Stats {
614
642
  colors.normal(reason.type);
615
643
  colors.normal(" ");
616
644
  colors.cyan(reason.userRequest);
617
- if(reason.templateModules) colors.cyan(reason.templateModules.join(" "));
618
645
  colors.normal(" [");
619
646
  colors.normal(reason.moduleId);
620
647
  colors.normal("] ");
@@ -758,6 +785,7 @@ class Stats {
758
785
  newline();
759
786
  }
760
787
  }
788
+
761
789
  if(obj._showWarnings && obj.warnings) {
762
790
  obj.warnings.forEach(warning => {
763
791
  newline();
@@ -18,6 +18,7 @@ const REGEXP_HASH_FOR_TEST = new RegExp(REGEXP_HASH.source, "i"),
18
18
  REGEXP_CHUNKHASH_FOR_TEST = new RegExp(REGEXP_CHUNKHASH.source, "i"),
19
19
  REGEXP_NAME_FOR_TEST = new RegExp(REGEXP_NAME.source, "i");
20
20
 
21
+ // TODO: remove in webpack 3
21
22
  // Backwards compatibility; expose regexes on Template object
22
23
  const Template = require("./Template");
23
24
  Template.REGEXP_HASH = REGEXP_HASH;
@@ -4,8 +4,9 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- class UnsupportedFeatureWarning extends Error {
7
+ const WebpackError = require("./WebpackError");
8
8
 
9
+ class UnsupportedFeatureWarning extends WebpackError {
9
10
  constructor(module, message) {
10
11
  super();
11
12
 
@@ -0,0 +1,11 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Jarid Margolin @jaridmargolin
4
+ */
5
+ "use strict";
6
+
7
+ module.exports = class WebpackError extends Error {
8
+ inspect() {
9
+ return this.stack + (this.details ? `\n${this.details}` : "");
10
+ }
11
+ };
@@ -81,7 +81,7 @@ class WebpackOptionsApply extends OptionsApply {
81
81
  let WebWorkerTemplatePlugin = require("./webworker/WebWorkerTemplatePlugin");
82
82
  NodeSourcePlugin = require("./node/NodeSourcePlugin");
83
83
  compiler.apply(
84
- new WebWorkerTemplatePlugin(options.output),
84
+ new WebWorkerTemplatePlugin(),
85
85
  new FunctionModulePlugin(options.output),
86
86
  new NodeSourcePlugin(options.node),
87
87
  new LoaderTargetPlugin("webworker")
@@ -206,9 +206,9 @@ class WebpackOptionsApply extends OptionsApply {
206
206
  noSources = options.devtool.indexOf("nosources") >= 0;
207
207
  legacy = options.devtool.indexOf("@") >= 0;
208
208
  modern = options.devtool.indexOf("#") >= 0;
209
- comment = legacy && modern ? "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/" :
210
- legacy ? "\n/*\n//@ sourceMappingURL=[url]\n*/" :
211
- modern ? "\n//# sourceMappingURL=[url]" :
209
+ comment = legacy && modern ? "\n/*\n//@ source" + "MappingURL=[url]\n//# source" + "MappingURL=[url]\n*/" :
210
+ legacy ? "\n/*\n//@ source" + "MappingURL=[url]\n*/" :
211
+ modern ? "\n//# source" + "MappingURL=[url]" :
212
212
  null;
213
213
  let Plugin = evalWrapped ? EvalSourceMapDevToolPlugin : SourceMapDevToolPlugin;
214
214
  compiler.apply(new Plugin({
@@ -4,6 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ const WebpackError = require("./WebpackError");
7
8
  const webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");
8
9
 
9
10
  const getSchemaPart = (path, parents, additionalPath) => {
@@ -46,13 +47,11 @@ const indent = (str, prefix, firstLine) => {
46
47
  }
47
48
  };
48
49
 
49
- class WebpackOptionsValidationError extends Error {
50
-
50
+ class WebpackOptionsValidationError extends WebpackError {
51
51
  constructor(validationErrors) {
52
52
  super();
53
53
 
54
54
  this.name = "WebpackOptionsValidationError";
55
-
56
55
  this.message = "Invalid configuration object. " +
57
56
  "Webpack has been initialised using a configuration object that does not match the API schema.\n" +
58
57
  validationErrors.map(err => " - " + indent(WebpackOptionsValidationError.formatValidationError(err), " ", false)).join("\n");
@@ -6,12 +6,13 @@
6
6
  const NullDependency = require("./NullDependency");
7
7
 
8
8
  class AMDDefineDependency extends NullDependency {
9
- constructor(range, arrayRange, functionRange, objectRange) {
9
+ constructor(range, arrayRange, functionRange, objectRange, namedModule) {
10
10
  super();
11
11
  this.range = range;
12
12
  this.arrayRange = arrayRange;
13
13
  this.functionRange = functionRange;
14
14
  this.objectRange = objectRange;
15
+ this.namedModule = namedModule;
15
16
  }
16
17
 
17
18
  get type() {
@@ -56,17 +57,16 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate {
56
57
  __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))`
57
58
  ],
58
59
  lf: [
59
- "var XXX;",
60
- "!(XXX = #.call(exports, __webpack_require__, exports, module))"
60
+ "var XXX, XXXmodule;",
61
+ "!(XXXmodule = { id: YYY, exports: {}, loaded: false }, XXX = #.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule), XXXmodule.loaded = true, XXX === undefined && (XXX = XXXmodule.exports))"
61
62
  ],
62
63
  lo: [
63
64
  "var XXX;",
64
65
  "!(XXX = #)"
65
66
  ],
66
67
  lof: [
67
- "var __WEBPACK_AMD_DEFINE_FACTORY__, XXX;",
68
- `!(__WEBPACK_AMD_DEFINE_FACTORY__ = (#), XXX = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
69
- (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__))`
68
+ "var XXX, XXXfactory, XXXmodule;",
69
+ "!(XXXfactory = (#), (XXXmodule = { id: YYY, exports: {}, loaded: false }), XXX = (typeof XXXfactory === 'function' ? (XXXfactory.call(XXXmodule.exports, __webpack_require__, XXXmodule.exports, XXXmodule)) : XXXfactory), (XXXmodule.loaded = true), XXX === undefined && (XXX = XXXmodule.exports))"
70
70
  ],
71
71
  laf: [
72
72
  "var __WEBPACK_AMD_DEFINE_ARRAY__, XXX;",
@@ -112,6 +112,10 @@ AMDDefineDependency.Template = class AMDDefineDependencyTemplate {
112
112
  definition = definition.replace(/XXX/g, localModuleVar.replace(/\$/g, "$$$$"));
113
113
  }
114
114
 
115
+ if(dependency.namedModule) {
116
+ text = text.replace(/YYY/g, JSON.stringify(dependency.namedModule));
117
+ }
118
+
115
119
  const texts = text.split("#");
116
120
 
117
121
  if(definition) source.insert(0, definition);
@@ -155,7 +155,14 @@ class AMDDefineDependencyParserPlugin {
155
155
  } else if(fn || obj) {
156
156
  parser.walkExpression(fn || obj);
157
157
  }
158
- const dep = new AMDDefineDependency(expr.range, array ? array.range : null, fn ? fn.range : null, obj ? obj.range : null);
158
+
159
+ const dep = new AMDDefineDependency(
160
+ expr.range,
161
+ array ? array.range : null,
162
+ fn ? fn.range : null,
163
+ obj ? obj.range : null,
164
+ namedModule ? namedModule : null
165
+ );
159
166
  dep.loc = expr.loc;
160
167
  if(namedModule) {
161
168
  dep.localModule = LocalModulesHelpers.addLocalModule(parser.state, namedModule);
@@ -61,10 +61,10 @@ class AMDPlugin {
61
61
  if(typeof parserOptions.amd !== "undefined" && !parserOptions.amd)
62
62
  return;
63
63
 
64
- function setExpressionToModule(expr, module) {
65
- parser.plugin("expression " + expr, (expr) => {
64
+ function setExpressionToModule(outerExpr, module) {
65
+ parser.plugin("expression " + outerExpr, (expr) => {
66
66
  const dep = new AMDRequireItemDependency(module, expr.range);
67
- dep.userRequest = expr;
67
+ dep.userRequest = outerExpr;
68
68
  dep.loc = expr.loc;
69
69
  parser.state.current.addDependency(dep);
70
70
  return true;