Skip to content

Commit dfc7825

Browse files
committed
chore: bump version to 0.1.9
1 parent b687db9 commit dfc7825

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ swc_html = { version = "=0.148.0" }
7979
swc_html_minifier = { version = "=0.145.0", default-features = false }
8080
swc_node_comments = { version = "=0.24.0" }
8181

82-
rspack_dojang = { version = "0.1.8" }
82+
rspack_dojang = { version = "0.1.9" }
8383
[workspace.metadata.release]
8484
rate-limit = { existing-packages = 70, new-packages = 70 }
8585
[profile.dev]

crates/rspack_plugin_html/src/plugin.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ use rspack_core::{
1515
Plugin,
1616
};
1717
use rspack_dojang::dojang::{Dojang, DojangOptions};
18+
use rspack_dojang::Operand;
1819
use rspack_error::{miette, AnyhowError, Diagnostic, Result};
1920
use rspack_hook::{plugin, plugin_hook};
2021
use rspack_paths::AssertUtf8;
2122
use rspack_util::infallible::ResultInfallibleExt as _;
23+
use serde_json::Value;
2224
use sugar_path::SugarPath;
2325
use swc_html::visit::VisitMutWith;
2426

@@ -286,10 +288,6 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
286288
.collect::<Vec<_>>(),
287289
);
288290

289-
for tag in tags.iter_mut() {
290-
tag.html = Some(html_tag_object_to_string(tag));
291-
}
292-
293291
let mut render_data = serde_json::json!(&self.config.template_parameters);
294292

295293
let mut body_tags = vec![];
@@ -312,9 +310,7 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
312310
"htmlRspackPlugin": {
313311
"tags": {
314312
"headTags": head_tags,
315-
"headTagsHtml": head_tags.iter().map(|tag| tag.html.clone().unwrap_or_default()).collect::<Vec<_>>().join(""),
316313
"bodyTags": body_tags,
317-
"bodyTagsHtml": body_tags.iter().map(|tag| tag.html.clone().unwrap_or_default()).collect::<Vec<_>>().join(""),
318314
},
319315
"files": {
320316
"favicon": favicon,
@@ -353,6 +349,9 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
353349
unescape: "=".to_string(),
354350
});
355351

352+
dj.add_function_1("toHtml".into(), render_tag)
353+
.expect("failed to add template function `renderTag`");
354+
356355
dj.add_with_option(url.clone(), content.clone())
357356
.expect("failed to add template");
358357
let mut template_result = match dj.render(&url, render_data) {
@@ -514,3 +513,22 @@ fn url_encode_path(file_path: &str) -> String {
514513
query_string.replace("&", "$$RSPACK_URL_AMP$$")
515514
)
516515
}
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+
}

crates/rspack_plugin_html/src/visitors/asset.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use serde::Serialize;
1+
use serde::{Deserialize, Serialize};
22
use swc_core::{common::DUMMY_SP, ecma::atoms::Atom};
33
use swc_html::ast::{Child, Element, Namespace, Text};
44
use swc_html::visit::{VisitMut, VisitMutWith};
@@ -9,7 +9,7 @@ use crate::config::{HtmlInject, HtmlRspackPluginOptions};
99

1010
// attributes are presented as plain string.
1111
// namespace is not supported currently.
12-
#[derive(Debug, Serialize)]
12+
#[derive(Debug, Serialize, Deserialize)]
1313
#[serde(rename_all = "camelCase")]
1414
pub struct HtmlPluginAttribute {
1515
pub attr_name: String,

crates/rspack_plugin_html/src/visitors/tag.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::collections::HashMap;
22

33
use itertools::Itertools;
4-
use serde::Serialize;
4+
use serde::{Deserialize, Serialize};
55

66
use super::asset::HtmlPluginAttribute;
77
use crate::config::{HtmlInject, HtmlRspackPluginBaseOptions, HtmlScriptLoading};
88

9-
#[derive(Debug, Default, Serialize)]
9+
#[derive(Debug, Default, Serialize, Deserialize)]
1010
#[serde(rename_all = "camelCase")]
1111
pub struct HTMLPluginTag {
1212
pub tag_name: String,
@@ -16,7 +16,6 @@ pub struct HTMLPluginTag {
1616
// `head`, `body`, `false`
1717
#[serde(skip)]
1818
pub append_to: HtmlInject,
19-
pub html: Option<String>,
2019
}
2120

2221
impl HTMLPluginTag {

0 commit comments

Comments
 (0)