Skip to content

Commit f4c00ef

Browse files
authored
fix: resolve issue #22842 skip ignored CSS imports with exportType style (#22846)
1 parent e7c2acf commit f4c00ef

5 files changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Fix crash when a CSS module with `exportType: "style"` imports an ignored stylesheet.

‎lib/css/CssGenerator.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ class CssGenerator extends Generator {
851851
const depModule = /** @type {CssModule & BuiltCssModule} */ (
852852
moduleGraph.getModule(dep)
853853
);
854+
if (!depModule) continue;
854855
if (concatenationScope && concatenationScope.isModuleInScope(depModule)) {
855856
continue;
856857
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import "./style.css";
2+
3+
it("should compile and inject styles even when @import is ignored", () => {
4+
const styles = Array.from(document.getElementsByTagName("style"));
5+
expect(styles.some(s => s.textContent.includes(".test"))).toBe(true);
6+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "./ignored.css";
2+
3+
.test {
4+
color: green;
5+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
3+
const webpack = require("../../../../");
4+
5+
/** @type {import("../../../../").Configuration} */
6+
module.exports = {
7+
target: "web",
8+
mode: "development",
9+
module: {
10+
rules: [
11+
{
12+
test: /\.css$/,
13+
type: "css/auto",
14+
parser: {
15+
exportType: "style"
16+
}
17+
}
18+
]
19+
},
20+
experiments: {
21+
css: true
22+
},
23+
plugins: [
24+
new webpack.IgnorePlugin({
25+
resourceRegExp: /ignored\.css$/
26+
})
27+
]
28+
};

0 commit comments

Comments
 (0)