webpack 3.5.2 → 3.5.6
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 +567 -567
- package/bin/config-yargs.js +1 -1
- package/bin/convert-argv.js +4 -4
- package/lib/Compilation.js +178 -144
- package/lib/Compiler.js +17 -17
- package/lib/ContextModuleFactory.js +6 -6
- package/lib/HotModuleReplacement.runtime.js +602 -594
- package/lib/Module.js +250 -248
- package/lib/NormalModule.js +556 -555
- package/lib/OptionsDefaulter.js +73 -71
- package/lib/Parser.js +10 -10
- package/lib/SourceMapDevToolPlugin.js +209 -207
- package/lib/Template.js +176 -166
- package/lib/UmdMainTemplatePlugin.js +6 -6
- package/lib/WebpackOptionsDefaulter.js +129 -115
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +285 -286
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +124 -121
- package/lib/dependencies/HarmonyModulesHelpers.js +85 -85
- package/lib/optimize/ConcatenatedModule.js +814 -807
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +9 -0
- package/lib/util/Semaphore.js +32 -0
- package/lib/webpack.js +119 -118
- package/package.json +1 -1
- package/schemas/webpackOptionsSchema.json +5 -0
package/lib/OptionsDefaulter.js
CHANGED
@@ -1,71 +1,73 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
function getProperty(obj, name) {
|
8
|
-
name = name.split(".");
|
9
|
-
for(var i = 0; i < name.length - 1; i++) {
|
10
|
-
obj = obj[name[i]];
|
11
|
-
if(typeof obj !== "object" || !obj) return;
|
12
|
-
}
|
13
|
-
return obj[name.pop()];
|
14
|
-
}
|
15
|
-
|
16
|
-
function setProperty(obj, name, value) {
|
17
|
-
name = name.split(".");
|
18
|
-
for(var i = 0; i < name.length - 1; i++) {
|
19
|
-
if(typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined") return;
|
20
|
-
if(!obj[name[i]]) obj[name[i]] = {};
|
21
|
-
obj = obj[name[i]];
|
22
|
-
}
|
23
|
-
obj[name.pop()] = value;
|
24
|
-
}
|
25
|
-
|
26
|
-
class OptionsDefaulter {
|
27
|
-
constructor() {
|
28
|
-
this.defaults = {};
|
29
|
-
this.config = {};
|
30
|
-
}
|
31
|
-
|
32
|
-
process(options) {
|
33
|
-
for
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
this.
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
}
|
70
|
-
|
71
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
function getProperty(obj, name) {
|
8
|
+
name = name.split(".");
|
9
|
+
for(var i = 0; i < name.length - 1; i++) {
|
10
|
+
obj = obj[name[i]];
|
11
|
+
if(typeof obj !== "object" || !obj) return;
|
12
|
+
}
|
13
|
+
return obj[name.pop()];
|
14
|
+
}
|
15
|
+
|
16
|
+
function setProperty(obj, name, value) {
|
17
|
+
name = name.split(".");
|
18
|
+
for(var i = 0; i < name.length - 1; i++) {
|
19
|
+
if(typeof obj[name[i]] !== "object" && typeof obj[name[i]] !== "undefined") return;
|
20
|
+
if(!obj[name[i]]) obj[name[i]] = {};
|
21
|
+
obj = obj[name[i]];
|
22
|
+
}
|
23
|
+
obj[name.pop()] = value;
|
24
|
+
}
|
25
|
+
|
26
|
+
class OptionsDefaulter {
|
27
|
+
constructor() {
|
28
|
+
this.defaults = {};
|
29
|
+
this.config = {};
|
30
|
+
}
|
31
|
+
|
32
|
+
process(options) {
|
33
|
+
// TODO: change this for webpack 4: options = Object.assign({}, options);
|
34
|
+
for(let name in this.defaults) {
|
35
|
+
switch(this.config[name]) {
|
36
|
+
case undefined:
|
37
|
+
if(getProperty(options, name) === undefined)
|
38
|
+
setProperty(options, name, this.defaults[name]);
|
39
|
+
break;
|
40
|
+
case "call":
|
41
|
+
setProperty(options, name, this.defaults[name].call(this, getProperty(options, name), options), options);
|
42
|
+
break;
|
43
|
+
case "make":
|
44
|
+
if(getProperty(options, name) === undefined)
|
45
|
+
setProperty(options, name, this.defaults[name].call(this, options), options);
|
46
|
+
break;
|
47
|
+
case "append":
|
48
|
+
{
|
49
|
+
let oldValue = getProperty(options, name);
|
50
|
+
if(!Array.isArray(oldValue)) oldValue = [];
|
51
|
+
oldValue.push.apply(oldValue, this.defaults[name]);
|
52
|
+
setProperty(options, name, oldValue);
|
53
|
+
break;
|
54
|
+
}
|
55
|
+
default:
|
56
|
+
throw new Error("OptionsDefaulter cannot process " + this.config[name]);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
// TODO: change this for webpack 4: return options;
|
60
|
+
}
|
61
|
+
|
62
|
+
set(name, config, def) {
|
63
|
+
if(arguments.length === 3) {
|
64
|
+
this.defaults[name] = def;
|
65
|
+
this.config[name] = config;
|
66
|
+
} else {
|
67
|
+
this.defaults[name] = config;
|
68
|
+
delete this.config[name];
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
module.exports = OptionsDefaulter;
|
package/lib/Parser.js
CHANGED
@@ -634,14 +634,14 @@ class Parser extends Tapable {
|
|
634
634
|
statement.params.forEach(param => {
|
635
635
|
this.walkPattern(param);
|
636
636
|
});
|
637
|
-
this.inScope(statement.params,
|
637
|
+
this.inScope(statement.params, () => {
|
638
638
|
if(statement.body.type === "BlockStatement") {
|
639
639
|
this.prewalkStatement(statement.body);
|
640
640
|
this.walkStatement(statement.body);
|
641
641
|
} else {
|
642
642
|
this.walkExpression(statement.body);
|
643
643
|
}
|
644
|
-
}
|
644
|
+
});
|
645
645
|
}
|
646
646
|
|
647
647
|
prewalkImportDeclaration(statement) {
|
@@ -784,10 +784,10 @@ class Parser extends Tapable {
|
|
784
784
|
}
|
785
785
|
|
786
786
|
walkCatchClause(catchClause) {
|
787
|
-
this.inScope([catchClause.param],
|
787
|
+
this.inScope([catchClause.param], () => {
|
788
788
|
this.prewalkStatement(catchClause.body);
|
789
789
|
this.walkStatement(catchClause.body);
|
790
|
-
}
|
790
|
+
});
|
791
791
|
}
|
792
792
|
|
793
793
|
prewalkVariableDeclarators(declarators) {
|
@@ -916,28 +916,28 @@ class Parser extends Tapable {
|
|
916
916
|
expression.params.forEach(param => {
|
917
917
|
this.walkPattern(param);
|
918
918
|
});
|
919
|
-
this.inScope(expression.params,
|
919
|
+
this.inScope(expression.params, () => {
|
920
920
|
if(expression.body.type === "BlockStatement") {
|
921
921
|
this.prewalkStatement(expression.body);
|
922
922
|
this.walkStatement(expression.body);
|
923
923
|
} else {
|
924
924
|
this.walkExpression(expression.body);
|
925
925
|
}
|
926
|
-
}
|
926
|
+
});
|
927
927
|
}
|
928
928
|
|
929
929
|
walkArrowFunctionExpression(expression) {
|
930
930
|
expression.params.forEach(param => {
|
931
931
|
this.walkPattern(param);
|
932
932
|
});
|
933
|
-
this.inScope(expression.params,
|
933
|
+
this.inScope(expression.params, () => {
|
934
934
|
if(expression.body.type === "BlockStatement") {
|
935
935
|
this.prewalkStatement(expression.body);
|
936
936
|
this.walkStatement(expression.body);
|
937
937
|
} else {
|
938
938
|
this.walkExpression(expression.body);
|
939
939
|
}
|
940
|
-
}
|
940
|
+
});
|
941
941
|
}
|
942
942
|
|
943
943
|
walkSequenceExpression(expression) {
|
@@ -1059,7 +1059,7 @@ class Parser extends Tapable {
|
|
1059
1059
|
const args = options.map(renameArgOrThis, this);
|
1060
1060
|
this.inScope(params.filter(function(identifier, idx) {
|
1061
1061
|
return !args[idx];
|
1062
|
-
}),
|
1062
|
+
}), () => {
|
1063
1063
|
if(renameThis) {
|
1064
1064
|
this.scope.renames.$this = renameThis;
|
1065
1065
|
}
|
@@ -1074,7 +1074,7 @@ class Parser extends Tapable {
|
|
1074
1074
|
this.walkStatement(functionExpression.body);
|
1075
1075
|
} else
|
1076
1076
|
this.walkExpression(functionExpression.body);
|
1077
|
-
}
|
1077
|
+
});
|
1078
1078
|
}
|
1079
1079
|
if(expression.callee.type === "MemberExpression" &&
|
1080
1080
|
expression.callee.object.type === "FunctionExpression" &&
|
@@ -1,207 +1,209 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const path = require("path");
|
8
|
-
const crypto = require("crypto");
|
9
|
-
const RequestShortener = require("./RequestShortener");
|
10
|
-
const ConcatSource = require("webpack-sources").ConcatSource;
|
11
|
-
const RawSource = require("webpack-sources").RawSource;
|
12
|
-
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
13
|
-
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
14
|
-
|
15
|
-
const basename = (name) => {
|
16
|
-
if(name.indexOf("/") < 0) return name;
|
17
|
-
return name.substr(name.lastIndexOf("/") + 1);
|
18
|
-
};
|
19
|
-
|
20
|
-
function getTaskForFile(file, chunk, options, compilation) {
|
21
|
-
const asset = compilation.assets[file];
|
22
|
-
if(asset.__SourceMapDevToolFile === file && asset.__SourceMapDevToolData) {
|
23
|
-
const data = asset.__SourceMapDevToolData;
|
24
|
-
for(const cachedFile in data) {
|
25
|
-
compilation.assets[cachedFile] = data[cachedFile];
|
26
|
-
if(cachedFile !== file)
|
27
|
-
chunk.files.push(cachedFile);
|
28
|
-
}
|
29
|
-
return;
|
30
|
-
}
|
31
|
-
let source, sourceMap;
|
32
|
-
if(asset.sourceAndMap) {
|
33
|
-
const sourceAndMap = asset.sourceAndMap(options);
|
34
|
-
sourceMap = sourceAndMap.map;
|
35
|
-
source = sourceAndMap.source;
|
36
|
-
} else {
|
37
|
-
sourceMap = asset.map(options);
|
38
|
-
source = asset.source();
|
39
|
-
}
|
40
|
-
if(sourceMap) {
|
41
|
-
return {
|
42
|
-
chunk,
|
43
|
-
file,
|
44
|
-
asset,
|
45
|
-
source,
|
46
|
-
sourceMap,
|
47
|
-
modules: undefined
|
48
|
-
};
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
class SourceMapDevToolPlugin {
|
53
|
-
constructor(options) {
|
54
|
-
if(arguments.length > 1)
|
55
|
-
throw new Error("SourceMapDevToolPlugin only takes one argument (pass an options object)");
|
56
|
-
// TODO: remove in webpack 3
|
57
|
-
if(typeof options === "string") {
|
58
|
-
options = {
|
59
|
-
sourceMapFilename: options
|
60
|
-
};
|
61
|
-
}
|
62
|
-
if(!options) options = {};
|
63
|
-
this.sourceMapFilename = options.filename;
|
64
|
-
this.sourceMappingURLComment = options.append === false ? false : options.append || "\n//# sourceMappingURL=[url]";
|
65
|
-
this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resourcePath]";
|
66
|
-
this.fallbackModuleFilenameTemplate = options.fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
|
67
|
-
this.options = options;
|
68
|
-
}
|
69
|
-
|
70
|
-
apply(compiler) {
|
71
|
-
const sourceMapFilename = this.sourceMapFilename;
|
72
|
-
const sourceMappingURLComment = this.sourceMappingURLComment;
|
73
|
-
const moduleFilenameTemplate = this.moduleFilenameTemplate;
|
74
|
-
const fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
|
75
|
-
const requestShortener = new RequestShortener(compiler.context);
|
76
|
-
const options = this.options;
|
77
|
-
options.test = options.test || /\.(js|css)($|\?)/i;
|
78
|
-
|
79
|
-
const matchObject = ModuleFilenameHelpers.matchObject.bind(undefined, options);
|
80
|
-
|
81
|
-
compiler.plugin("compilation", compilation => {
|
82
|
-
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
83
|
-
|
84
|
-
compilation.plugin("after-optimize-chunk-assets", function(chunks) {
|
85
|
-
const moduleToSourceNameMapping = new Map();
|
86
|
-
const tasks = [];
|
87
|
-
|
88
|
-
chunks.forEach(function(chunk) {
|
89
|
-
chunk.files.forEach(file => {
|
90
|
-
if(matchObject(file)) {
|
91
|
-
const task = getTaskForFile(file, chunk, options, compilation);
|
92
|
-
|
93
|
-
if(task) {
|
94
|
-
const modules = task.sourceMap.sources.map(source => {
|
95
|
-
const module = compilation.findModule(source);
|
96
|
-
return module || source;
|
97
|
-
});
|
98
|
-
|
99
|
-
for(
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
const
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
const
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
const
|
153
|
-
const
|
154
|
-
const
|
155
|
-
const
|
156
|
-
const
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
sourceMap.sourcesContent =
|
162
|
-
}
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const path = require("path");
|
8
|
+
const crypto = require("crypto");
|
9
|
+
const RequestShortener = require("./RequestShortener");
|
10
|
+
const ConcatSource = require("webpack-sources").ConcatSource;
|
11
|
+
const RawSource = require("webpack-sources").RawSource;
|
12
|
+
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
13
|
+
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
14
|
+
|
15
|
+
const basename = (name) => {
|
16
|
+
if(name.indexOf("/") < 0) return name;
|
17
|
+
return name.substr(name.lastIndexOf("/") + 1);
|
18
|
+
};
|
19
|
+
|
20
|
+
function getTaskForFile(file, chunk, options, compilation) {
|
21
|
+
const asset = compilation.assets[file];
|
22
|
+
if(asset.__SourceMapDevToolFile === file && asset.__SourceMapDevToolData) {
|
23
|
+
const data = asset.__SourceMapDevToolData;
|
24
|
+
for(const cachedFile in data) {
|
25
|
+
compilation.assets[cachedFile] = data[cachedFile];
|
26
|
+
if(cachedFile !== file)
|
27
|
+
chunk.files.push(cachedFile);
|
28
|
+
}
|
29
|
+
return;
|
30
|
+
}
|
31
|
+
let source, sourceMap;
|
32
|
+
if(asset.sourceAndMap) {
|
33
|
+
const sourceAndMap = asset.sourceAndMap(options);
|
34
|
+
sourceMap = sourceAndMap.map;
|
35
|
+
source = sourceAndMap.source;
|
36
|
+
} else {
|
37
|
+
sourceMap = asset.map(options);
|
38
|
+
source = asset.source();
|
39
|
+
}
|
40
|
+
if(sourceMap) {
|
41
|
+
return {
|
42
|
+
chunk,
|
43
|
+
file,
|
44
|
+
asset,
|
45
|
+
source,
|
46
|
+
sourceMap,
|
47
|
+
modules: undefined
|
48
|
+
};
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
class SourceMapDevToolPlugin {
|
53
|
+
constructor(options) {
|
54
|
+
if(arguments.length > 1)
|
55
|
+
throw new Error("SourceMapDevToolPlugin only takes one argument (pass an options object)");
|
56
|
+
// TODO: remove in webpack 3
|
57
|
+
if(typeof options === "string") {
|
58
|
+
options = {
|
59
|
+
sourceMapFilename: options
|
60
|
+
};
|
61
|
+
}
|
62
|
+
if(!options) options = {};
|
63
|
+
this.sourceMapFilename = options.filename;
|
64
|
+
this.sourceMappingURLComment = options.append === false ? false : options.append || "\n//# sourceMappingURL=[url]";
|
65
|
+
this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resourcePath]";
|
66
|
+
this.fallbackModuleFilenameTemplate = options.fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
|
67
|
+
this.options = options;
|
68
|
+
}
|
69
|
+
|
70
|
+
apply(compiler) {
|
71
|
+
const sourceMapFilename = this.sourceMapFilename;
|
72
|
+
const sourceMappingURLComment = this.sourceMappingURLComment;
|
73
|
+
const moduleFilenameTemplate = this.moduleFilenameTemplate;
|
74
|
+
const fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
|
75
|
+
const requestShortener = new RequestShortener(compiler.context);
|
76
|
+
const options = this.options;
|
77
|
+
options.test = options.test || /\.(js|css)($|\?)/i;
|
78
|
+
|
79
|
+
const matchObject = ModuleFilenameHelpers.matchObject.bind(undefined, options);
|
80
|
+
|
81
|
+
compiler.plugin("compilation", compilation => {
|
82
|
+
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
83
|
+
|
84
|
+
compilation.plugin("after-optimize-chunk-assets", function(chunks) {
|
85
|
+
const moduleToSourceNameMapping = new Map();
|
86
|
+
const tasks = [];
|
87
|
+
|
88
|
+
chunks.forEach(function(chunk) {
|
89
|
+
chunk.files.forEach(file => {
|
90
|
+
if(matchObject(file)) {
|
91
|
+
const task = getTaskForFile(file, chunk, options, compilation);
|
92
|
+
|
93
|
+
if(task) {
|
94
|
+
const modules = task.sourceMap.sources.map(source => {
|
95
|
+
const module = compilation.findModule(source);
|
96
|
+
return module || source;
|
97
|
+
});
|
98
|
+
|
99
|
+
for(let idx = 0; idx < modules.length; idx++) {
|
100
|
+
const module = modules[idx];
|
101
|
+
if(!moduleToSourceNameMapping.get(module)) {
|
102
|
+
moduleToSourceNameMapping.set(module, ModuleFilenameHelpers.createFilename(module, moduleFilenameTemplate, requestShortener));
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
task.modules = modules;
|
107
|
+
|
108
|
+
tasks.push(task);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
});
|
112
|
+
});
|
113
|
+
|
114
|
+
const usedNamesSet = new Set(moduleToSourceNameMapping.values());
|
115
|
+
const conflictDetectionSet = new Set();
|
116
|
+
|
117
|
+
// all modules in defined order (longest identifier first)
|
118
|
+
const allModules = Array.from(moduleToSourceNameMapping.keys()).sort((a, b) => {
|
119
|
+
const ai = typeof a === "string" ? a : a.identifier();
|
120
|
+
const bi = typeof b === "string" ? b : b.identifier();
|
121
|
+
return ai.length - bi.length;
|
122
|
+
});
|
123
|
+
|
124
|
+
// find modules with conflicting source names
|
125
|
+
for(let idx = 0; idx < allModules.length; idx++) {
|
126
|
+
const module = allModules[idx];
|
127
|
+
let sourceName = moduleToSourceNameMapping.get(module);
|
128
|
+
let hasName = conflictDetectionSet.has(sourceName);
|
129
|
+
if(!hasName) {
|
130
|
+
conflictDetectionSet.add(sourceName);
|
131
|
+
continue;
|
132
|
+
}
|
133
|
+
|
134
|
+
// try the fallback name first
|
135
|
+
sourceName = ModuleFilenameHelpers.createFilename(module, fallbackModuleFilenameTemplate, requestShortener);
|
136
|
+
hasName = usedNamesSet.has(sourceName);
|
137
|
+
if(!hasName) {
|
138
|
+
moduleToSourceNameMapping.set(module, sourceName);
|
139
|
+
usedNamesSet.add(sourceName);
|
140
|
+
continue;
|
141
|
+
}
|
142
|
+
|
143
|
+
// elsewise just append stars until we have a valid name
|
144
|
+
while(hasName) {
|
145
|
+
sourceName += "*";
|
146
|
+
hasName = usedNamesSet.has(sourceName);
|
147
|
+
}
|
148
|
+
moduleToSourceNameMapping.set(module, sourceName);
|
149
|
+
usedNamesSet.add(sourceName);
|
150
|
+
}
|
151
|
+
tasks.forEach(function(task) {
|
152
|
+
const chunk = task.chunk;
|
153
|
+
const file = task.file;
|
154
|
+
const asset = task.asset;
|
155
|
+
const sourceMap = task.sourceMap;
|
156
|
+
const source = task.source;
|
157
|
+
const modules = task.modules;
|
158
|
+
const moduleFilenames = modules.map(m => moduleToSourceNameMapping.get(m));
|
159
|
+
sourceMap.sources = moduleFilenames;
|
160
|
+
if(sourceMap.sourcesContent && !options.noSources) {
|
161
|
+
sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}`);
|
162
|
+
} else {
|
163
|
+
sourceMap.sourcesContent = undefined;
|
164
|
+
}
|
165
|
+
sourceMap.sourceRoot = options.sourceRoot || "";
|
166
|
+
sourceMap.file = file;
|
167
|
+
asset.__SourceMapDevToolFile = file;
|
168
|
+
asset.__SourceMapDevToolData = {};
|
169
|
+
let currentSourceMappingURLComment = sourceMappingURLComment;
|
170
|
+
if(currentSourceMappingURLComment !== false && /\.css($|\?)/i.test(file)) {
|
171
|
+
currentSourceMappingURLComment = currentSourceMappingURLComment.replace(/^\n\/\/(.*)$/, "\n/*$1*/");
|
172
|
+
}
|
173
|
+
const sourceMapString = JSON.stringify(sourceMap);
|
174
|
+
if(sourceMapFilename) {
|
175
|
+
let filename = file;
|
176
|
+
let query = "";
|
177
|
+
const idx = filename.indexOf("?");
|
178
|
+
if(idx >= 0) {
|
179
|
+
query = filename.substr(idx);
|
180
|
+
filename = filename.substr(0, idx);
|
181
|
+
}
|
182
|
+
let sourceMapFile = compilation.getPath(sourceMapFilename, {
|
183
|
+
chunk,
|
184
|
+
filename,
|
185
|
+
query,
|
186
|
+
basename: basename(filename)
|
187
|
+
});
|
188
|
+
if(sourceMapFile.indexOf("[contenthash]") !== -1) {
|
189
|
+
sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex"));
|
190
|
+
}
|
191
|
+
const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
|
192
|
+
if(currentSourceMappingURLComment !== false) {
|
193
|
+
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
|
194
|
+
}
|
195
|
+
asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(sourceMapString);
|
196
|
+
chunk.files.push(sourceMapFile);
|
197
|
+
} else {
|
198
|
+
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
|
199
|
+
.replace(/\[map\]/g, () => sourceMapString)
|
200
|
+
.replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(sourceMapString, "utf-8").toString("base64")}`) // eslint-disable-line
|
201
|
+
);
|
202
|
+
}
|
203
|
+
});
|
204
|
+
});
|
205
|
+
});
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
module.exports = SourceMapDevToolPlugin;
|