@@ -6,8 +6,8 @@ use rspack_collections::IdentifierSet;
66use rspack_core:: {
77 ChunkGraph , ChunkGroup , ChunkGroupUkey , ChunkUkey , Compilation , CompilationAfterProcessAssets ,
88 CompilationParams , CompilerCompilation , CompilerFailed , CompilerId , CompilerMake ,
9- CrossOriginLoading , DependenciesBlock , Dependency , DependencyId , DependencyType , Logger ,
10- ModuleGraph , ModuleId , ModuleIdentifier , Plugin ,
9+ CrossOriginLoading , DependenciesBlock , Dependency , DependencyId , DependencyType , EntryDependency ,
10+ Logger , ModuleGraph , ModuleId , ModuleIdentifier , Plugin ,
1111} ;
1212use rspack_error:: { Diagnostic , Result } ;
1313use rspack_hook:: { plugin, plugin_hook} ;
@@ -98,8 +98,8 @@ fn record_module(
9898
9999 if is_css_mod ( module. as_ref ( ) ) {
100100 let mut matched_server_entries = Vec :: new ( ) ;
101- for ( server_entry, imports ) in & entry_state. css_imports_per_server_entry {
102- if imports . contains ( resource. as_ref ( ) ) {
101+ for ( server_entry, server_entry_state ) in & entry_state. server_entries {
102+ if server_entry_state . css_imports . contains ( resource. as_ref ( ) ) {
103103 matched_server_entries. push ( server_entry. clone ( ) ) ;
104104 }
105105 }
@@ -128,9 +128,10 @@ fn record_module(
128128
129129 for server_entry in matched_server_entries {
130130 entry_state
131- . entry_css_files
132- . entry ( server_entry. clone ( ) )
131+ . server_entries
132+ . entry ( server_entry)
133133 . or_default ( )
134+ . css_files
134135 . extend ( css_files. clone ( ) ) ;
135136 }
136137
@@ -261,7 +262,10 @@ fn record_chunk_group(
261262 }
262263}
263264
264- fn collect_entry_js_files ( compilation : & Compilation , plugin_state : & mut PluginState ) -> Result < ( ) > {
265+ fn collect_bootstrap_scripts (
266+ compilation : & Compilation ,
267+ plugin_state : & mut PluginState ,
268+ ) -> Result < ( ) > {
265269 for ( entry_name, chunk_group_ukey) in & compilation. build_chunk_graph_artifact . entrypoints {
266270 let Some ( entry_state) = plugin_state. entries . get_mut ( entry_name. as_str ( ) ) else {
267271 continue ;
@@ -281,7 +285,7 @@ fn collect_entry_js_files(compilation: &Compilation, plugin_state: &mut PluginSt
281285 . expect ( "module_loading should be initialized in traverse_modules before recording modules" )
282286 . prefix ;
283287
284- let entry_js_files = chunk_group
288+ let bootstrap_scripts = chunk_group
285289 . get_files ( & compilation. build_chunk_graph_artifact . chunk_by_ukey )
286290 . into_iter ( )
287291 . filter ( |chunk_file| chunk_file. ends_with ( ".js" ) )
@@ -297,7 +301,7 @@ fn collect_entry_js_files(compilation: &Compilation, plugin_state: &mut PluginSt
297301 . map ( |file| prefixed_asset_path ( prefix, & file) )
298302 . collect :: < FxIndexSet < String > > ( ) ;
299303
300- entry_state. entry_js_files = entry_js_files ;
304+ entry_state. bootstrap_scripts = bootstrap_scripts ;
301305 }
302306 Ok ( ( ) )
303307}
@@ -520,6 +524,7 @@ async fn compilation(
520524 params : & mut CompilationParams ,
521525) -> Result < ( ) > {
522526 compilation. set_dependency_factory ( DependencyType :: RscEntry , Arc :: new ( RscEntryModuleFactory ) ) ;
527+ compilation. set_dependency_factory ( DependencyType :: Entry , params. normal_module_factory . clone ( ) ) ;
523528 compilation. set_dependency_factory (
524529 DependencyType :: RscClientReference ,
525530 params. normal_module_factory . clone ( ) ,
@@ -543,29 +548,30 @@ async fn make(&self, compilation: &mut Compilation) -> Result<()> {
543548 )
544549 } ) ?;
545550
546- let mut include_dependencies = vec ! [ ] ;
547551 for ( entry_name, entry_state) in & plugin_state. entries {
548552 let client_modules = & entry_state. injected_client_entries ;
549- {
550- if compilation. entries . get ( entry_name. as_ref ( ) ) . is_none ( ) {
551- compilation. push_diagnostic ( Diagnostic :: error (
552- "RSC Client Entry Mismatch" . to_string ( ) ,
553- format ! (
554- "Entry '{}' not found in the client compiler. Failed to inject the following client modules: {}" ,
555- entry_name,
556- client_modules
557- . iter( )
558- . map( |m| m. request. as_str( ) )
559- . collect:: <Vec <_>>( )
560- . join( ", " )
561- ) ,
562- ) ) ;
563- continue ;
564- }
553+ if compilation. entries . get ( entry_name. as_ref ( ) ) . is_none ( ) {
554+ compilation. push_diagnostic ( Diagnostic :: error (
555+ "RSC Client Entry Mismatch" . to_string ( ) ,
556+ format ! (
557+ "Entry '{}' not found in the client compiler. Failed to inject the following client modules: {}" ,
558+ entry_name,
559+ client_modules
560+ . iter( )
561+ . map( |m| m. request. as_str( ) )
562+ . collect:: <Vec <_>>( )
563+ . join( ", " )
564+ ) ,
565+ ) ) ;
566+ continue ;
567+ }
565568
569+ let mut include_dependencies = Vec :: new ( ) ;
570+ if !client_modules. is_empty ( ) || entry_state. has_css_imports_by_server_entry ( ) {
566571 let dependency = Box :: new ( RscEntryDependency :: new (
567572 entry_name. clone ( ) ,
568573 client_modules. clone ( ) ,
574+ entry_state. css_imports_by_server_entry ( ) ,
569575 false ,
570576 ) ) ;
571577 self
@@ -580,8 +586,23 @@ async fn make(&self, compilation: &mut Compilation) -> Result<()> {
580586 . add_dependency ( dependency) ;
581587 }
582588
589+ let mut entry_dependencies = Vec :: new ( ) ;
590+ for request in & entry_state. root_css_imports {
591+ let dependency = Box :: new ( EntryDependency :: new (
592+ request. clone ( ) ,
593+ compilation. options . context . clone ( ) ,
594+ None ,
595+ false ,
596+ ) ) ;
597+ entry_dependencies. push ( * dependency. id ( ) ) ;
598+ compilation
599+ . get_module_graph_mut ( )
600+ . add_dependency ( dependency) ;
601+ }
602+
583603 #[ allow( clippy:: unwrap_used) ]
584604 let entry_data = compilation. entries . get_mut ( entry_name. as_ref ( ) ) . unwrap ( ) ;
605+ entry_data. dependencies . append ( & mut entry_dependencies) ;
585606 entry_data
586607 . include_dependencies
587608 . append ( & mut include_dependencies) ;
@@ -614,8 +635,8 @@ async fn after_process_assets(
614635 self . traverse_modules ( compilation, & mut plugin_state) ?;
615636 logger. time_end ( start) ;
616637
617- let start = logger. time ( "record entry js files " ) ;
618- collect_entry_js_files ( compilation, & mut plugin_state) ?;
638+ let start = logger. time ( "record bootstrap scripts " ) ;
639+ collect_bootstrap_scripts ( compilation, & mut plugin_state) ?;
619640 logger. time_end ( start) ;
620641
621642 for ( entry_name, client_entries) in self . client_entries_per_entry . borrow ( ) . iter ( ) {
0 commit comments