Skip to content

Commit 60c5331

Browse files
fix: adding media, supports and layer for external import (#1072)
1 parent 82f4a47 commit 60c5331

File tree

6 files changed

+82
-2
lines changed

6 files changed

+82
-2
lines changed

src/index.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,11 +1368,32 @@ class MiniCssExtractPlugin {
13681368

13691369
// HACK for IE
13701370
// http://stackoverflow.com/a/14676665/1458162
1371-
if (module.media) {
1371+
if (
1372+
module.media ||
1373+
module.supports ||
1374+
typeof module.layer !== "undefined"
1375+
) {
1376+
let atImportExtra = "";
1377+
1378+
const needLayer = typeof module.layer !== "undefined";
1379+
1380+
if (needLayer) {
1381+
atImportExtra +=
1382+
module.layer.length > 0 ? ` layer(${module.layer})` : " layer";
1383+
}
1384+
1385+
if (module.supports) {
1386+
atImportExtra += ` supports(${module.supports})`;
1387+
}
1388+
1389+
if (module.media) {
1390+
atImportExtra += ` ${module.media}`;
1391+
}
1392+
13721393
// insert media into the @import
13731394
// this is rar
13741395
// TODO improve this and parse the CSS to support multiple medias
1375-
content = content.replace(/;|\s*$/, `${module.media};`);
1396+
content = content.replace(/;|\s*$/, `${atImportExtra};`);
13761397
}
13771398

13781399
externalsSource.add(content);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@import url(http://some/path/to/css1.css);
2+
@import url(http://some/path/to/css2.css) screen and (max-width: 1024px);
3+
@import url(http://some/path/to/css3.css) supports(display: grid) screen and
4+
(max-width: 400px);
5+
@import url(http://some/path/to/css4.css) supports(display: grid);
6+
@import url(http://some/path/to/css5.css) layer();
7+
@import url(http://some/path/to/css6.css) layer;
8+
@import url(http://some/path/to/css7.css) layer(layer-name)
9+
supports(display: grid) screen and (max-width: 1024px);
10+
@import url(http://some/path/to/css8.css) layer(layer-name) screen and
11+
(max-width: 1024px);
12+
13+
body {
14+
background: red;
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import url("https://some/external/css");
2+
3+
.b {
4+
background: red;
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@import url(http://some/path/to/css1.css);
2+
@import url(http://some/path/to/css2.css) screen and (max-width: 1024px);
3+
@import url(http://some/path/to/css3.css) supports(display: grid) screen and
4+
(max-width: 400px);
5+
@import url(http://some/path/to/css4.css) supports(display: grid);
6+
@import url(http://some/path/to/css5.css) layer;
7+
@import url(http://some/path/to/css6.css) layer;
8+
@import url(http://some/path/to/css7.css) layer(layer-name) supports(display: grid) screen and (max-width: 1024px);
9+
@import url(http://some/path/to/css8.css) layer(layer-name) screen and
10+
(max-width: 1024px);
11+
@import url(https://some/external/css);
12+
body {
13+
background: red;
14+
}
15+
16+
.b {
17+
background: red;
18+
}
19+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "./a.css";
2+
import "./b.css";
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Self from "../../../src";
2+
3+
module.exports = {
4+
entry: "./index.js",
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [Self.loader, "css-loader"],
10+
},
11+
],
12+
},
13+
plugins: [
14+
new Self({
15+
filename: "[name].css",
16+
}),
17+
],
18+
};

0 commit comments

Comments
 (0)