Skip to content

Commit 87dd7a2

Browse files
committed
cr fixes
1 parent d250eac commit 87dd7a2

File tree

7 files changed

+21
-38
lines changed

7 files changed

+21
-38
lines changed

lib/NamedModulesPlugin.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,33 @@ class NamedModulesPlugin {
2222
compiler.hooks.compilation.tap("NamedModulesPlugin", compilation => {
2323
compilation.hooks.beforeModuleIds.tap("NamedModulesPlugin", modules => {
2424
const namedModules = new Map();
25+
const context = this.options.context || compiler.options.context;
2526

2627
for (const module of modules) {
2728
if (module.id === null && module.libIdent) {
28-
module.id = module.libIdent({
29-
context: this.options.context || compiler.options.context
30-
});
29+
module.id = module.libIdent({ context });
3130
}
3231

3332
if (module.id !== null) {
34-
if (namedModules.has(module.id)) {
35-
namedModules.get(module.id).push(module);
33+
const namedModule = namedModules.get(module.id);
34+
if (namedModule !== undefined) {
35+
namedModule.push(module);
3636
} else {
3737
namedModules.set(module.id, [module]);
3838
}
3939
}
4040
}
4141

42-
namedModules.forEach(namedModule => {
42+
for (const namedModule of namedModules.values()) {
4343
if (namedModule.length > 1) {
44-
namedModule.forEach(module => {
45-
if (module.issuer && module.issuer.id) {
46-
const requestShortener = new RequestShortener(module.context);
47-
module.id = `${module.id}?${getHash(
48-
requestShortener.shorten(module.identifier())
49-
)}`;
50-
}
51-
});
44+
for (const module of namedModule) {
45+
const requestShortener = new RequestShortener(context);
46+
module.id = `${module.id}?${getHash(
47+
requestShortener.shorten(module.identifier())
48+
)}`;
49+
}
5250
}
53-
});
51+
}
5452
});
5553
});
5654
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = "c";
1+
module.exports = module.id;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = function(src) {
2-
return `module.exports = "loader-a"`;
2+
return `module.exports = "loader-a" + module.id`;
33
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = function(src) {
2-
return `module.exports = "loader-b"`;
2+
return `module.exports = "loader-b" + module.id`;
33
};

test/configCases/module-name/different-issuers-for-same-module/test.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
it("should assign different names to the same module with different issuers ", function() {
2-
var fs = require("fs");
3-
var path = require("path");
4-
var bundle = fs.readFileSync(path.join(__dirname, "main.js"), "utf-8");
5-
expect(bundle.match(/"\.\/c\.js\?\w{4}":/g)).toHaveLength(2);
6-
expect(require("./a")).toEqual("loader-a");
7-
expect(require("./b")).toEqual("loader-b");
2+
var regex = "\\./c\\.js\\?\\w{4}";
3+
expect(require("./c")).toMatch(new RegExp(regex));
4+
expect(require("./a")).toMatch(new RegExp("loader-a" + regex));
5+
expect(require("./b")).toMatch(new RegExp("loader-b" + regex));
86
});
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
module.exports = {
22
mode: "development",
3-
output: {
4-
filename: "main.js"
5-
},
6-
entry: {
7-
main: ["./a", "./b", "./test"]
8-
},
3+
entry: ["./a", "./b", "./test"],
94
module: {
105
rules: [
116
{
@@ -19,8 +14,5 @@ module.exports = {
1914
loader: "./loader-b"
2015
}
2116
]
22-
},
23-
node: {
24-
__dirname: false
2517
}
2618
};

0 commit comments

Comments
 (0)