Skip to content

Commit bf83b48

Browse files
authored
fix: set the correct asset_info when extracting css (#8454)
1 parent b5fd823 commit bf83b48

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

crates/rspack_plugin_extract_css/src/plugin.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use rspack_collections::{DatabaseItem, IdentifierMap, IdentifierSet, UkeySet};
77
use rspack_core::ChunkGraph;
88
use rspack_core::{
99
rspack_sources::{ConcatSource, RawSource, SourceMap, SourceMapSource, WithoutOriginalOptions},
10-
ApplyContext, AssetInfo, Chunk, ChunkGroupUkey, ChunkKind, ChunkUkey, Compilation,
11-
CompilationContentHash, CompilationParams, CompilationRenderManifest,
12-
CompilationRuntimeRequirementInTree, CompilerCompilation, CompilerOptions, Filename, Module,
13-
ModuleGraph, ModuleIdentifier, ModuleType, NormalModuleFactoryParser, ParserAndGenerator,
14-
ParserOptions, PathData, Plugin, PluginContext, RenderManifestEntry, RuntimeGlobals, SourceType,
10+
ApplyContext, Chunk, ChunkGroupUkey, ChunkKind, ChunkUkey, Compilation, CompilationContentHash,
11+
CompilationParams, CompilationRenderManifest, CompilationRuntimeRequirementInTree,
12+
CompilerCompilation, CompilerOptions, Filename, Module, ModuleGraph, ModuleIdentifier,
13+
ModuleType, NormalModuleFactoryParser, ParserAndGenerator, ParserOptions, PathData, Plugin,
14+
PluginContext, RenderManifestEntry, RuntimeGlobals, SourceType,
1515
};
1616
use rspack_error::{Diagnostic, Result};
1717
use rspack_hash::RspackHash;
@@ -315,7 +315,7 @@ impl PluginCssExtract {
315315
let mut source = ConcatSource::default();
316316
let mut external_source = ConcatSource::default();
317317

318-
let (filename, _) = compilation.get_path_with_info(filename_template, path_data)?;
318+
let (filename, asset_info) = compilation.get_path_with_info(filename_template, path_data)?;
319319

320320
for module in used_modules {
321321
let content = Cow::Borrowed(module.content.as_str());
@@ -412,7 +412,7 @@ impl PluginCssExtract {
412412
RenderManifestEntry::new(
413413
Arc::new(external_source),
414414
filename,
415-
AssetInfo::default(),
415+
asset_info,
416416
false,
417417
false,
418418
),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./style.css";
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { rspack } = require("@rspack/core");
2+
3+
class Plugin {
4+
apply(compiler) {
5+
compiler.hooks.thisCompilation.tap("MyPlugin", compilation => {
6+
compilation.hooks.processAssets.tap(
7+
{
8+
name: "MyPlugin",
9+
stage: compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH
10+
},
11+
() => {
12+
const css = compilation
13+
.getAssets()
14+
.find(asset => asset.name.endsWith(".css"));
15+
expect(css.info.contenthash.length).toBeGreaterThan(0);
16+
}
17+
);
18+
});
19+
}
20+
}
21+
22+
/** @type {import("@rspack/core").Configuration} */
23+
module.exports = {
24+
entry: "./index.js",
25+
target: "web",
26+
module: {
27+
rules: [
28+
{
29+
test: /\.css$/,
30+
use: [rspack.CssExtractRspackPlugin.loader, "css-loader"]
31+
}
32+
]
33+
},
34+
plugins: [
35+
new rspack.CssExtractRspackPlugin({
36+
filename: "[name].[contenthash].css"
37+
}),
38+
new Plugin()
39+
],
40+
experiments: {
41+
css: false
42+
}
43+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.example {
2+
margin-left: 22px;
3+
margin-top: 22px;
4+
margin-bottom: 22px;
5+
}

0 commit comments

Comments
 (0)