Skip to content

Commit 905a8f1

Browse files
authored
Merge pull request webpack#5986 from EugeneHlushko/feature-sourcemap-use-filename-in-url
SourceMapDevToolPlugin: Enable path stripping from source map filenam…
2 parents 5acbe2f + 471e1a2 commit 905a8f1

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

lib/SourceMapDevToolPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,14 @@ class SourceMapDevToolPlugin {
181181
}
182182
let sourceMapFile = compilation.getPath(sourceMapFilename, {
183183
chunk,
184-
filename,
184+
filename: options.fileContext ? path.relative(options.fileContext, filename) : filename,
185185
query,
186186
basename: basename(filename)
187187
});
188188
if(sourceMapFile.indexOf("[contenthash]") !== -1) {
189189
sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex"));
190190
}
191-
const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
191+
const sourceMapUrl = options.publicPath ? options.publicPath + sourceMapFile.replace(/\\/g, "/") : path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
192192
if(currentSourceMappingURLComment !== false) {
193193
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
194194
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
it("should contain publicPath prefix in [url] and resolve relatively to fileContext", function() {
2+
var fs = require("fs"),
3+
path = require("path");
4+
var source = fs.readFileSync(path.join(__dirname, "public/test.js"), "utf-8");
5+
source.should.containEql("//# sourceMappingURL=https://10.10.10.10/project/sourcemaps/test.js.map");
6+
});
7+
8+
it("should write sourcemap file relative fo fileContext", function() {
9+
var fs = require("fs"),
10+
path = require("path");
11+
fs.existsSync(path.join(__dirname, "sourcemaps/test.js.map")).should.be.true();
12+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var testObject = {
2+
a: 1
3+
};
4+
5+
module.exports = testObject;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var webpack = require("../../../../");
2+
module.exports = {
3+
node: {
4+
__dirname: false,
5+
__filename: false
6+
},
7+
entry: {
8+
"bundle0": ["./index.js"],
9+
"public/test": ["./test.js"],
10+
},
11+
output: {
12+
filename: "[name].js"
13+
},
14+
plugins: [
15+
new webpack.SourceMapDevToolPlugin({
16+
filename: "sourcemaps/[file].map",
17+
publicPath: "https://10.10.10.10/project/",
18+
fileContext: "public"
19+
})
20+
]
21+
};

0 commit comments

Comments
 (0)