Skip to content

Commit cee43e7

Browse files
authored
fix: avoid full hash runtime when not using full hash for css extract (#10936)
1 parent f979e1d commit cee43e7

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

crates/rspack_plugin_extract_css/src/plugin.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,7 @@ async fn runtime_requirement_in_tree(
523523
if runtime_requirements.contains(RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS)
524524
|| runtime_requirements.contains(RuntimeGlobals::ENSURE_CHUNK_HANDLERS)
525525
{
526-
if let Some(chunk_filename) = self.options.chunk_filename.template()
527-
&& chunk_filename.contains("hash")
528-
{
526+
if self.options.chunk_filename.has_hash_placeholder() {
529527
runtime_requirements_mut.insert(RuntimeGlobals::GET_FULL_HASH);
530528
}
531529

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.text {
2+
color: blue;
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
it("should not contain full hash runtime module", async () => {
2+
await import("./index.css");
3+
4+
const chunk = __non_webpack_require__("fs").readFileSync(__filename, "utf-8");
5+
const hashRuntime = ["__webpack_require__", "h"].join(".") // use join() here to avoid compile time evaluation
6+
expect(chunk).not.toContain(hashRuntime);
7+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { CssExtractRspackPlugin } = require("@rspack/core");
2+
3+
/** @type {import("@rspack/core").Configuration} */
4+
module.exports = {
5+
target: "web",
6+
node: {
7+
__filename: false
8+
},
9+
module: {
10+
rules: [
11+
{
12+
test: /\.css$/,
13+
use: [CssExtractRspackPlugin.loader, "css-loader"],
14+
type: "javascript/auto"
15+
}
16+
]
17+
},
18+
plugins: [
19+
new CssExtractRspackPlugin({
20+
filename: "[name][contenthash].css"
21+
})
22+
]
23+
};

0 commit comments

Comments
 (0)