Skip to content

Commit e3bb83a

Browse files
princedevilebottnawi
authored andcommitted
fix: support deduplication of string module ids (optimization.namedModules) (#789)
1 parent 10c3bc3 commit e3bb83a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/css-base.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = function(useSourceMap) {
2525
var alreadyImportedModules = {};
2626
for(var i = 0; i < this.length; i++) {
2727
var id = this[i][0];
28-
if(typeof id === "number")
28+
if(id != null)
2929
alreadyImportedModules[id] = true;
3030
}
3131
for(i = 0; i < modules.length; i++) {
@@ -34,7 +34,7 @@ module.exports = function(useSourceMap) {
3434
// this implementation is not 100% perfect for weird media query combinations
3535
// when a module is imported multiple times with different media queries.
3636
// I hope this will never occur (Hey this way we have smaller bundles)
37-
if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
37+
if(item[0] == null || !alreadyImportedModules[item[0]]) {
3838
if(mediaQuery && !item[2]) {
3939
item[2] = mediaQuery;
4040
} else if(mediaQuery) {

test/cssBaseTest.js

+15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ describe("css-base", function() {
5252
"@media print{body { d: 4; }}" +
5353
"@media screen{body { a: 1; }}");
5454
});
55+
it("should import named modules", function() {
56+
var m = base();
57+
var m1 = ["./module1", "body { a: 1; }", "screen"];
58+
var m2 = ["./module2", "body { b: 2; }", ""];
59+
var m3 = ["./module3", "body { c: 3; }", ""];
60+
var m4 = ["./module4", "body { d: 4; }", ""];
61+
m.i([m2, m3], "");
62+
m.i([m2], "");
63+
m.i([m2, m4], "print");
64+
m.push(m1);
65+
m.toString().should.be.eql("body { b: 2; }" +
66+
"body { c: 3; }" +
67+
"@media print{body { d: 4; }}" +
68+
"@media screen{body { a: 1; }}");
69+
});
5570
it("should toString with source mapping", function() {
5671
var m = base(true);
5772
m.push([1, "body { a: 1; }", "", {

0 commit comments

Comments
 (0)