Use resource path when possible for absoluteResourcePath

Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
Louis Chemineau 2021-11-16 16:59:28 +01:00
parent ccecc17c01
commit fdf28b84ed
4 changed files with 39 additions and 1 deletions

View File

@ -138,7 +138,8 @@ ModuleFilenameHelpers.createFilename = (
);
identifier = memoize(() => requestShortener.shorten(module.identifier()));
moduleId = () => chunkGraph.getModuleId(module);
absoluteResourcePath = () => module.identifier().split("!").pop();
absoluteResourcePath = () =>
requestShortener.shorten(module.nameForCondition());
hash = getHash(identifier, hashFunction);
}
const resource = memoize(() => shortIdentifier().split("!").pop());

View File

@ -0,0 +1,8 @@
it("should not include layer or type in absoluteResourcePath", function() {
var fs = require("fs");
var source = fs.readFileSync(__filename + ".map", "utf-8");
var map = JSON.parse(source);
expect(map.sources).toContain("webpack:///test.js");
});
if (Math.random() < 0) require("./test.js");

View File

@ -0,0 +1,3 @@
var foo = {};
module.exports = foo;

View File

@ -0,0 +1,26 @@
const path = require("path");
/** @type {import("../../../../").Configuration} */
module.exports = {
node: {
__dirname: false,
__filename: false
},
experiments: {
layers: true
},
devtool: "source-map",
entry: {
main: {
import: "./index",
layer: "something"
}
},
output: {
devtoolModuleFilenameTemplate(info) {
const rootDir = process.cwd();
const rel = path.relative(rootDir, info.absoluteResourcePath);
return `webpack:///${rel}`;
}
}
};