diff --git a/src/builder.rs b/src/builder.rs index d81408740..b5d107046 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -462,7 +462,8 @@ pub fn gen_page(config: &DioxusConfig, serve: bool) -> String { { style_str.push_str("\n"); } - html = html.replace("{style_include}", &style_str); + + replace_or_insert_before("{style_include}", &style_str, " String { )) } - html = html.replace("{script_include}", &script_str); + replace_or_insert_before("{script_include}", &script_str, " String { ); } - html = html.replace("{app_name}", &config.application.name); - - html = match &config.web.app.base_path { - Some(path) => html.replace("{base_path}", path), - None => html.replace("{base_path}", "."), + let base_path = match &config.web.app.base_path { + Some(path) => path, + None => ".", }; + let app_name = &config.application.name; + // Check if a script already exists + if html.contains("{app_name}") && html.contains("{base_path}") { + html = html.replace("{app_name}", app_name); + + html = html.replace("{base_path}", base_path); + } else { + // If not, insert the script + html = html.replace( + " + import init from "/{base_path}/assets/dioxus/{app_name}.js"; + init("/{base_path}/assets/dioxus/{app_name}_bg.wasm").then(wasm => {{ + if (wasm.__wbindgen_start == undefined) {{ + wasm.main(); + }} + }}); + + String { .clone() .unwrap_or_else(|| "dioxus | ⛺".into()); - html.replace("{app_title}", &title) + replace_or_insert_before("{app_title}", &title, "