Skip to content

Commit 6752a9c

Browse files
rafdesokra
authored andcommitted
Enable use of sourceMapFilename: "[file].map?[contenthash]" as a useful workaround for this bug in chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=508270
1 parent 9c1ab27 commit 6752a9c

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/SourceMapDevToolPlugin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"use strict";
66

77
const path = require("path");
8+
const crypto = require("crypto");
89
const RequestShortener = require("./RequestShortener");
910
const ConcatSource = require("webpack-sources").ConcatSource;
1011
const RawSource = require("webpack-sources").RawSource;
@@ -145,7 +146,10 @@ class SourceMapDevToolPlugin {
145146
query,
146147
basename: basename(filename)
147148
});
148-
const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
149+
let sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
150+
if(sourceMapUrl.indexOf("[contenthash]") !== -1) {
151+
sourceMapUrl = sourceMapUrl.replace(/\[contenthash\]/g, crypto.createHash("md5").update(source).digest("hex"));
152+
}
149153
if(currentSourceMappingURLComment !== false) {
150154
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
151155
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
it("should contain contenthash as query parameter and path", function() {
2+
var fs = require("fs");
3+
var source = fs.readFileSync(__filename, "utf-8");
4+
var match = /sourceMappingURL\s*=.*-([A-Fa-f0-9]{32})\.map\?([A-Fa-f0-9]{32})-([A-Fa-f0-9]{32})/.exec(source);
5+
match.length.should.be.eql(4);
6+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var webpack = require("../../../../");
2+
module.exports = {
3+
node: {
4+
__dirname: false,
5+
__filename: false
6+
},
7+
devtool: "source-map",
8+
output: {
9+
sourceMapFilename: "[file]-[contenthash].map?[contenthash]-[contenthash]",
10+
},
11+
plugins: [
12+
new webpack.optimize.UglifyJsPlugin({
13+
sourceMap: true
14+
})
15+
]
16+
};

0 commit comments

Comments
 (0)