webpack 2.3.1 → 2.4.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.
- package/README.md +139 -132
- package/lib/APIPlugin.js +0 -6
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/CachePlugin.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +6 -3
- package/lib/ChunkRenderError.js +3 -1
- package/lib/ChunkTemplate.js +2 -2
- package/lib/Compilation.js +3 -3
- package/lib/Compiler.js +1 -1
- package/lib/ContextModule.js +3 -2
- package/lib/ContextModuleFactory.js +5 -5
- package/lib/DelegatedModule.js +67 -63
- package/lib/DependenciesBlock.js +65 -59
- package/lib/Dependency.js +1 -0
- package/lib/EntryModuleNotFoundError.js +16 -10
- package/lib/ExtendedAPIPlugin.js +7 -2
- package/lib/ExternalModuleFactoryPlugin.js +26 -23
- package/lib/FlagDependencyUsagePlugin.js +63 -75
- package/lib/HotModuleReplacement.runtime.js +25 -27
- package/lib/HotModuleReplacementPlugin.js +3 -5
- package/lib/IgnorePlugin.js +48 -17
- package/lib/JsonpChunkTemplatePlugin.js +24 -24
- package/lib/JsonpMainTemplatePlugin.js +182 -182
- package/lib/LibManifestPlugin.js +51 -46
- package/lib/MainTemplate.js +17 -18
- package/lib/Module.js +158 -160
- package/lib/ModuleBuildError.js +4 -2
- package/lib/ModuleDependencyError.js +2 -1
- package/lib/ModuleDependencyWarning.js +2 -1
- package/lib/ModuleError.js +2 -2
- package/lib/ModuleFilenameHelpers.js +27 -27
- package/lib/ModuleNotFoundError.js +3 -1
- package/lib/ModuleParseError.js +6 -4
- package/lib/ModuleWarning.js +2 -2
- package/lib/MultiCompiler.js +3 -4
- package/lib/MultiStats.js +3 -3
- package/lib/MultiWatching.js +2 -2
- package/lib/NamedChunksPlugin.js +30 -0
- package/lib/NodeStuffPlugin.js +80 -79
- package/lib/NormalModule.js +6 -2
- package/lib/NormalModuleFactory.js +244 -240
- package/lib/Parser.js +1256 -1079
- package/lib/ProgressPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +5 -9
- package/lib/SetVarMainTemplatePlugin.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +153 -157
- package/lib/Stats.js +32 -5
- package/lib/TemplatedPathPlugin.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +2 -1
- package/lib/WebpackError.js +11 -0
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/WebpackOptionsValidationError.js +8 -4
- package/lib/dependencies/AMDDefineDependency.js +10 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -1
- package/lib/dependencies/AMDPlugin.js +3 -3
- package/lib/dependencies/ContextDependencyHelpers.js +19 -16
- package/lib/dependencies/CriticalDependencyWarning.js +4 -1
- package/lib/dependencies/DepBlockHelpers.js +3 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -2
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportDependenciesBlock.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +16 -2
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +11 -3
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +42 -13
- package/lib/dependencies/RequireEnsureDependency.js +9 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -17
- package/lib/optimize/CommonsChunkPlugin.js +1 -1
- package/lib/performance/AssetsOverSizeLimitWarning.js +4 -1
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +5 -1
- package/lib/performance/NoAsyncChunksWarning.js +5 -1
- package/lib/removeAndDo.js +6 -4
- package/lib/util/identifier.js +16 -0
- package/lib/webpack.js +2 -1
- package/package.json +4 -3
- package/schemas/ajv.absolutePath.js +1 -1
- package/schemas/webpackOptionsSchema.json +27 -0
package/lib/ProgressPlugin.js
CHANGED
@@ -23,7 +23,7 @@ class ProgressPlugin {
|
|
23
23
|
if(compiler.compilers) {
|
24
24
|
const states = new Array(compiler.compilers.length);
|
25
25
|
compiler.compilers.forEach(function(compiler, idx) {
|
26
|
-
compiler.apply(new ProgressPlugin((p, msg)
|
26
|
+
compiler.apply(new ProgressPlugin(function(p, msg) {
|
27
27
|
states[idx] = Array.prototype.slice.apply(arguments);
|
28
28
|
handler.apply(null, [
|
29
29
|
states.map(state => state && state[0] || 0).reduce((a, b) => a + b) / states.length,
|
package/lib/RecordIdsPlugin.js
CHANGED
@@ -4,14 +4,10 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
|
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 =
|
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 =
|
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(
|
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",
|
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
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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 =
|
62
|
-
source = asset.source();
|
124
|
+
sourceMap.sourcesContent = undefined;
|
63
125
|
}
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
-
|
150
|
-
|
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
|
}
|
@@ -70,6 +98,7 @@ class Stats {
|
|
70
98
|
const showErrors = optionOrFallback(options.errors, true);
|
71
99
|
const showErrorDetails = optionOrFallback(options.errorDetails, !forToString);
|
72
100
|
const showWarnings = optionOrFallback(options.warnings, true);
|
101
|
+
const warningsFilter = optionOrFallback(options.warningsFilter, null);
|
73
102
|
const showPublicPath = optionOrFallback(options.publicPath, !forToString);
|
74
103
|
const excludeModules = [].concat(optionOrFallback(options.exclude, [])).map(str => {
|
75
104
|
if(typeof str !== "string") return str;
|
@@ -155,7 +184,7 @@ class Stats {
|
|
155
184
|
|
156
185
|
const obj = {
|
157
186
|
errors: compilation.errors.map(formatError),
|
158
|
-
warnings: compilation.warnings.map(formatError)
|
187
|
+
warnings: Stats.filterWarnings(compilation.warnings.map(formatError), warningsFilter)
|
159
188
|
};
|
160
189
|
|
161
190
|
//We just hint other renderers since actually omitting
|
@@ -270,9 +299,7 @@ class Stats {
|
|
270
299
|
type: reason.dependency.type,
|
271
300
|
userRequest: reason.dependency.userRequest
|
272
301
|
};
|
273
|
-
const
|
274
|
-
if(dep.templateModules) obj.templateModules = dep.templateModules.map(module => module.id);
|
275
|
-
const locInfo = formatLocation(dep.loc);
|
302
|
+
const locInfo = formatLocation(reason.dependency.loc);
|
276
303
|
if(locInfo) obj.loc = locInfo;
|
277
304
|
return obj;
|
278
305
|
}).sort((a, b) => a.moduleId - b.moduleId);
|
@@ -614,7 +641,6 @@ class Stats {
|
|
614
641
|
colors.normal(reason.type);
|
615
642
|
colors.normal(" ");
|
616
643
|
colors.cyan(reason.userRequest);
|
617
|
-
if(reason.templateModules) colors.cyan(reason.templateModules.join(" "));
|
618
644
|
colors.normal(" [");
|
619
645
|
colors.normal(reason.moduleId);
|
620
646
|
colors.normal("] ");
|
@@ -758,6 +784,7 @@ class Stats {
|
|
758
784
|
newline();
|
759
785
|
}
|
760
786
|
}
|
787
|
+
|
761
788
|
if(obj._showWarnings && obj.warnings) {
|
762
789
|
obj.warnings.forEach(warning => {
|
763
790
|
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;
|
@@ -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(
|
84
|
+
new WebWorkerTemplatePlugin(),
|
85
85
|
new FunctionModulePlugin(options.output),
|
86
86
|
new NodeSourcePlugin(options.node),
|
87
87
|
new LoaderTargetPlugin("webworker")
|
@@ -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
|
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");
|
@@ -181,7 +180,12 @@ class WebpackOptionsValidationError extends Error {
|
|
181
180
|
else
|
182
181
|
return `${dataPath} ${err.message}`;
|
183
182
|
} else if(err.keyword === "absolutePath") {
|
184
|
-
|
183
|
+
const baseMessage = `${dataPath}: ${err.message}`;
|
184
|
+
if(dataPath === "configuration.output.filename") {
|
185
|
+
return `${baseMessage}\n` +
|
186
|
+
"Please use output.path to specify absolute path and output.filename for the file name.";
|
187
|
+
}
|
188
|
+
return baseMessage;
|
185
189
|
} else {
|
186
190
|
// eslint-disable-line no-fallthrough
|
187
191
|
return `${dataPath} ${err.message} (${JSON.stringify(err, 0, 2)}).\n${getSchemaPartText(err.parentSchema)}`;
|
@@ -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,
|
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
|
68
|
-
|
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
|
-
|
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(
|
65
|
-
parser.plugin("expression " +
|
64
|
+
function setExpressionToModule(outerExpr, module) {
|
65
|
+
parser.plugin("expression " + outerExpr, (expr) => {
|
66
66
|
const dep = new AMDRequireItemDependency(module, expr.range);
|
67
|
-
dep.userRequest =
|
67
|
+
dep.userRequest = outerExpr;
|
68
68
|
dep.loc = expr.loc;
|
69
69
|
parser.state.current.addDependency(dep);
|
70
70
|
return true;
|