Skip to content

Commit 22c9b5b

Browse files
authored
fix(css): should generate css assets even if the imported css file is empty (#2747)
* fix(css): should generate css assets even if the imported css file is empty * Tweak
1 parent 944b25e commit 22c9b5b

File tree

8 files changed

+56
-1
lines changed

8 files changed

+56
-1
lines changed

crates/rspack_plugin_css/src/plugin.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,11 @@ impl Plugin for CssPlugin {
701701
output
702702
})
703703
.collect::<Vec<ConcatSource>>();
704+
let is_no_sources = sources.is_empty();
705+
704706
let source = ConcatSource::new(sources);
705707

706-
if source.source().is_empty() {
708+
if is_no_sources {
707709
Ok(Default::default())
708710
} else {
709711
let filename_template = get_css_chunk_filename_template(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "test-case",
3+
"private": true,
4+
"dependencies": {}
5+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/** @type { import('@rspack/core').RspackOptions } */
2+
module.exports = {
3+
context: __dirname,
4+
mode: "development",
5+
entry: "./src/index.js",
6+
devServer: {
7+
hot: true
8+
},
9+
cache: false,
10+
stats: "none",
11+
infrastructureLogging: {
12+
debug: false
13+
},
14+
builtins: {
15+
html: [
16+
{
17+
template: "./src/index.html"
18+
}
19+
],
20+
define: {
21+
"process.env.NODE_ENV": JSON.stringify("development")
22+
}
23+
},
24+
watchOptions: {
25+
poll: 1000
26+
}
27+
};

packages/playground/fixtures/import-empty-css-file/src/empty.css

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./empty.css";
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
</body>
12+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import("./empty").then(() => {
2+
document.getElementById("root").innerText = "ok";
3+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test("should not throw error for importing empty css files", async () => {
2+
expect(await page.textContent("#root")).toBe("ok");
3+
});
4+
5+
export {};

0 commit comments

Comments
 (0)