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.
@@ -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(let name in this.defaults) {
34
- switch(this.config[name]) {
35
- case undefined:
36
- if(getProperty(options, name) === undefined)
37
- setProperty(options, name, this.defaults[name]);
38
- break;
39
- case "call":
40
- setProperty(options, name, this.defaults[name].call(this, getProperty(options, name), options), options);
41
- break;
42
- case "make":
43
- if(getProperty(options, name) === undefined)
44
- setProperty(options, name, this.defaults[name].call(this, options), options);
45
- break;
46
- case "append":
47
- {
48
- let oldValue = getProperty(options, name);
49
- if(!Array.isArray(oldValue)) oldValue = [];
50
- oldValue.push.apply(oldValue, this.defaults[name]);
51
- setProperty(options, name, oldValue);
52
- break;
53
- }
54
- default:
55
- throw new Error("OptionsDefaulter cannot process " + this.config[name]);
56
- }
57
- }
58
- }
59
-
60
- set(name, config, def) {
61
- if(arguments.length === 3) {
62
- this.defaults[name] = def;
63
- this.config[name] = config;
64
- } else {
65
- this.defaults[name] = config;
66
- delete this.config[name];
67
- }
68
- }
69
- }
70
-
71
- module.exports = OptionsDefaulter;
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, function() {
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
- }.bind(this));
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], function() {
787
+ this.inScope([catchClause.param], () => {
788
788
  this.prewalkStatement(catchClause.body);
789
789
  this.walkStatement(catchClause.body);
790
- }.bind(this));
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, function() {
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
- }.bind(this));
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, function() {
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
- }.bind(this));
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
- }), function() {
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
- }.bind(this));
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(const module of modules) {
100
- if(!moduleToSourceNameMapping.get(module)) {
101
- moduleToSourceNameMapping.set(module, ModuleFilenameHelpers.createFilename(module, moduleFilenameTemplate, requestShortener));
102
- }
103
- }
104
-
105
- task.modules = modules;
106
-
107
- tasks.push(task);
108
- }
109
- }
110
- });
111
- });
112
-
113
- const usedNamesSet = new Set(moduleToSourceNameMapping.values());
114
- const conflictDetectionSet = new Set();
115
-
116
- // all modules in defined order (longest identifier first)
117
- const allModules = Array.from(moduleToSourceNameMapping.keys()).sort((a, b) => {
118
- const ai = typeof a === "string" ? a : a.identifier();
119
- const bi = typeof b === "string" ? b : b.identifier();
120
- return ai.length - bi.length;
121
- });
122
-
123
- // find modules with conflicting source names
124
- for(const module of allModules) {
125
- let sourceName = moduleToSourceNameMapping.get(module);
126
- let hasName = conflictDetectionSet.has(sourceName);
127
- if(!hasName) {
128
- conflictDetectionSet.add(sourceName);
129
- continue;
130
- }
131
-
132
- // try the fallback name first
133
- sourceName = ModuleFilenameHelpers.createFilename(module, fallbackModuleFilenameTemplate, requestShortener);
134
- hasName = usedNamesSet.has(sourceName);
135
- if(!hasName) {
136
- moduleToSourceNameMapping.set(module, sourceName);
137
- usedNamesSet.add(sourceName);
138
- continue;
139
- }
140
-
141
- // elsewise just append stars until we have a valid name
142
- while(hasName) {
143
- sourceName += "*";
144
- hasName = usedNamesSet.has(sourceName);
145
- }
146
- moduleToSourceNameMapping.set(module, sourceName);
147
- usedNamesSet.add(sourceName);
148
- }
149
- tasks.forEach(function(task) {
150
- const chunk = task.chunk;
151
- const file = task.file;
152
- const asset = task.asset;
153
- const sourceMap = task.sourceMap;
154
- const source = task.source;
155
- const modules = task.modules;
156
- const moduleFilenames = modules.map(m => moduleToSourceNameMapping.get(m));
157
- sourceMap.sources = moduleFilenames;
158
- if(sourceMap.sourcesContent && !options.noSources) {
159
- sourceMap.sourcesContent = sourceMap.sourcesContent.map((content, i) => `${content}\n\n\n${ModuleFilenameHelpers.createFooter(modules[i], requestShortener)}`);
160
- } else {
161
- sourceMap.sourcesContent = undefined;
162
- }
163
- sourceMap.sourceRoot = options.sourceRoot || "";
164
- sourceMap.file = file;
165
- asset.__SourceMapDevToolFile = file;
166
- asset.__SourceMapDevToolData = {};
167
- let currentSourceMappingURLComment = sourceMappingURLComment;
168
- if(currentSourceMappingURLComment !== false && /\.css($|\?)/i.test(file)) {
169
- currentSourceMappingURLComment = currentSourceMappingURLComment.replace(/^\n\/\/(.*)$/, "\n/*$1*/");
170
- }
171
- const sourceMapString = JSON.stringify(sourceMap);
172
- if(sourceMapFilename) {
173
- let filename = file;
174
- let query = "";
175
- const idx = filename.indexOf("?");
176
- if(idx >= 0) {
177
- query = filename.substr(idx);
178
- filename = filename.substr(0, idx);
179
- }
180
- let sourceMapFile = compilation.getPath(sourceMapFilename, {
181
- chunk,
182
- filename,
183
- query,
184
- basename: basename(filename)
185
- });
186
- if(sourceMapFile.indexOf("[contenthash]") !== -1) {
187
- sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex"));
188
- }
189
- const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
190
- if(currentSourceMappingURLComment !== false) {
191
- asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
192
- }
193
- asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(sourceMapString);
194
- chunk.files.push(sourceMapFile);
195
- } else {
196
- asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
197
- .replace(/\[map\]/g, () => sourceMapString)
198
- .replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(sourceMapString, "utf-8").toString("base64")}`) // eslint-disable-line
199
- );
200
- }
201
- });
202
- });
203
- });
204
- }
205
- }
206
-
207
- module.exports = SourceMapDevToolPlugin;
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;