@@ -15,10 +15,12 @@ use rspack_core::{
15
15
Plugin ,
16
16
} ;
17
17
use rspack_dojang:: dojang:: { Dojang , DojangOptions } ;
18
+ use rspack_dojang:: Operand ;
18
19
use rspack_error:: { miette, AnyhowError , Diagnostic , Result } ;
19
20
use rspack_hook:: { plugin, plugin_hook} ;
20
21
use rspack_paths:: AssertUtf8 ;
21
22
use rspack_util:: infallible:: ResultInfallibleExt as _;
23
+ use serde_json:: Value ;
22
24
use sugar_path:: SugarPath ;
23
25
use swc_html:: visit:: VisitMutWith ;
24
26
@@ -286,10 +288,6 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
286
288
. collect :: < Vec < _ > > ( ) ,
287
289
) ;
288
290
289
- for tag in tags. iter_mut ( ) {
290
- tag. html = Some ( html_tag_object_to_string ( tag) ) ;
291
- }
292
-
293
291
let mut render_data = serde_json:: json!( & self . config. template_parameters) ;
294
292
295
293
let mut body_tags = vec ! [ ] ;
@@ -312,9 +310,7 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
312
310
"htmlRspackPlugin" : {
313
311
"tags" : {
314
312
"headTags" : head_tags,
315
- "headTagsHtml" : head_tags. iter( ) . map( |tag| tag. html. clone( ) . unwrap_or_default( ) ) . collect:: <Vec <_>>( ) . join( "" ) ,
316
313
"bodyTags" : body_tags,
317
- "bodyTagsHtml" : body_tags. iter( ) . map( |tag| tag. html. clone( ) . unwrap_or_default( ) ) . collect:: <Vec <_>>( ) . join( "" ) ,
318
314
} ,
319
315
"files" : {
320
316
"favicon" : favicon,
@@ -353,6 +349,9 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
353
349
unescape : "=" . to_string ( ) ,
354
350
} ) ;
355
351
352
+ dj. add_function_1 ( "toHtml" . into ( ) , render_tag)
353
+ . expect ( "failed to add template function `renderTag`" ) ;
354
+
356
355
dj. add_with_option ( url. clone ( ) , content. clone ( ) )
357
356
. expect ( "failed to add template" ) ;
358
357
let mut template_result = match dj. render ( & url, render_data) {
@@ -514,3 +513,22 @@ fn url_encode_path(file_path: &str) -> String {
514
513
query_string. replace( "&" , "$$RSPACK_URL_AMP$$" )
515
514
)
516
515
}
516
+
517
+ pub fn render_tag ( op : Operand ) -> Operand {
518
+ match op {
519
+ Operand :: Value ( obj) => match serde_json:: from_value :: < HTMLPluginTag > ( obj) {
520
+ Ok ( tag) => Operand :: Value ( Value :: from ( html_tag_object_to_string ( & tag) ) ) ,
521
+ Err ( _) => Operand :: Value ( Value :: from ( "" ) ) ,
522
+ } ,
523
+ Operand :: Array ( obj) => Operand :: Value ( Value :: from (
524
+ obj
525
+ . iter ( )
526
+ . map ( |val| match render_tag ( val. to_owned ( ) ) {
527
+ Operand :: Value ( val) => val. as_str ( ) . unwrap_or_default ( ) . to_string ( ) ,
528
+ _ => "" . to_string ( ) ,
529
+ } )
530
+ . join ( "" ) ,
531
+ ) ) ,
532
+ _ => Operand :: Value ( Value :: from ( "" ) ) ,
533
+ }
534
+ }
0 commit comments