Skip to content

Commit

Permalink
fix: module identifier, don't merge modules with different media/supp…
Browse files Browse the repository at this point in the history
…ors/layer (#1021)
  • Loading branch information
alexander-akait authored Mar 16, 2023
1 parent e0ca181 commit ad3729b
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class MiniCssExtractPlugin {
}

identifier() {
return `css|${this._identifier}|${this._identifierIndex}`;
return `css|${this._identifier}|${this._identifierIndex}|${this.layer}|${this.supports}|${this.media}}}`;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/cases/issue-css-loader-1503-1/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: black;
}
4 changes: 4 additions & 0 deletions test/cases/issue-css-loader-1503-1/expected/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background: black;
}

8 changes: 8 additions & 0 deletions test/cases/issue-css-loader-1503-1/expected/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@supports (display: flex) {
body {
background: black;
}

}


1 change: 1 addition & 0 deletions test/cases/issue-css-loader-1503-1/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url("dark.css") supports(display: flex);
31 changes: 31 additions & 0 deletions test/cases/issue-css-loader-1503-1/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Self from "../../../src";

module.exports = {
entry: {
dark: "./dark.css",
index: "./index.css",
},
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: Self.loader,
},
{
loader: "css-loader",
options: {
modules: true,
},
},
],
},
],
},
plugins: [
new Self({
filename: "[name].css",
}),
],
};
3 changes: 3 additions & 0 deletions test/cases/issue-css-loader-1503-2/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: black;
}
4 changes: 4 additions & 0 deletions test/cases/issue-css-loader-1503-2/expected/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background: black;
}

8 changes: 8 additions & 0 deletions test/cases/issue-css-loader-1503-2/expected/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@layer framework.component {
body {
background: black;
}

}


1 change: 1 addition & 0 deletions test/cases/issue-css-loader-1503-2/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url("dark.css") layer(framework.component);
31 changes: 31 additions & 0 deletions test/cases/issue-css-loader-1503-2/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Self from "../../../src";

module.exports = {
entry: {
dark: "./dark.css",
index: "./index.css",
},
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: Self.loader,
},
{
loader: "css-loader",
options: {
modules: true,
},
},
],
},
],
},
plugins: [
new Self({
filename: "[name].css",
}),
],
};
3 changes: 3 additions & 0 deletions test/cases/issue-css-loader-1503/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: black;
}
4 changes: 4 additions & 0 deletions test/cases/issue-css-loader-1503/expected/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background: black;
}

8 changes: 8 additions & 0 deletions test/cases/issue-css-loader-1503/expected/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@media (prefers-color-scheme: dark) {
body {
background: black;
}

}


1 change: 1 addition & 0 deletions test/cases/issue-css-loader-1503/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "./dark.css" (prefers-color-scheme: dark);
31 changes: 31 additions & 0 deletions test/cases/issue-css-loader-1503/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Self from "../../../src";

module.exports = {
entry: {
dark: "./dark.css",
index: "./index.css",
},
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: Self.loader,
},
{
loader: "css-loader",
options: {
modules: true,
},
},
],
},
],
},
plugins: [
new Self({
filename: "[name].css",
}),
],
};

0 comments on commit ad3729b

Please sign in to comment.