diff --git a/examples/basic/.perseus/server/src/main.rs b/examples/basic/.perseus/server/src/main.rs index 32db0c7dd6..36a513213d 100644 --- a/examples/basic/.perseus/server/src/main.rs +++ b/examples/basic/.perseus/server/src/main.rs @@ -116,6 +116,8 @@ fn get_props(is_standalone: bool) -> ServerProps>) -> std::io::Result>) -> std::io::Result { NamedFile::open(&opts.wasm_bundle) } +async fn wasm_js_bundle(opts: web::Data>) -> std::io::Result { + NamedFile::open(&opts.wasm_js_bundle) +} async fn static_alias( opts: web::Data>, req: HttpRequest, @@ -79,6 +82,7 @@ pub async fn configurer HtmlShell<'a> { } // Define the script that will load the Wasm bundle (inlined to avoid unnecessary extra requests) + // If we're using the `wasm2js` feature, this will try to load a JS version instead (expected to be at `/.perseus/bundle.wasm.js`) + #[cfg(not(feature = "wasm2js"))] let load_wasm_bundle = format!( r#" import init, {{ run }} from "{path_prefix}/.perseus/bundle.js"; @@ -72,6 +74,18 @@ impl<'a> HtmlShell<'a> { "#, path_prefix = path_prefix ); + #[cfg(feature = "wasm2js")] + let load_wasm_bundle = format!( + r#" + import init, {{ run }} from "{path_prefix}/.perseus/bundle.js"; + async function main() {{ + await init("{path_prefix}/.perseus/bundle.wasm.js"); + run(); + }} + main(); + "#, + path_prefix = path_prefix + ); scripts_before_boundary.push(load_wasm_bundle.into()); // Add in the `` element at the very top so that it applies to everything in the HTML shell diff --git a/packages/perseus/src/server/options.rs b/packages/perseus/src/server/options.rs index 4842f0df09..926c730cf2 100644 --- a/packages/perseus/src/server/options.rs +++ b/packages/perseus/src/server/options.rs @@ -15,6 +15,8 @@ pub struct ServerOptions { pub js_bundle: String, /// The location on the filesystem of your Wasm bundle. pub wasm_bundle: String, + /// The location on the filesystem of your JS bundle converted from your Wasm bundle. This isn't required, and if you haven't generated this, you should provide a fake path. + pub wasm_js_bundle: String, /// The location on the filesystem of your `index.html` file. // TODO Should this actually be a raw string of HTML so plugins can inject efficiently? pub index: String,