From d2484fb23788cfc715e74e4fca8982b725dddf86 Mon Sep 17 00:00:00 2001 From: Jens Reimann Date: Mon, 18 Dec 2023 18:12:46 +0100 Subject: [PATCH] fix: apply correct top level mode to worker loader script --- src/pipelines/rust/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pipelines/rust/mod.rs b/src/pipelines/rust/mod.rs index 91125d91..19c37ce4 100644 --- a/src/pipelines/rust/mod.rs +++ b/src/pipelines/rust/mod.rs @@ -532,9 +532,16 @@ impl RustApp { "copying {js_loader_path} to {}", js_loader_path_dist.display() ); - self.copy_or_minify_js(js_loader_path, &js_loader_path_dist) - .await - .context("error minifying or copying JS loader file to stage dir")?; + self.copy_or_minify_js( + js_loader_path, + &js_loader_path_dist, + match self.wasm_bindgen_target { + WasmBindgenTarget::NoModules => TopLevelMode::Global, + _ => TopLevelMode::Module, + }, + ) + .await + .context("error minifying or copying JS loader file to stage dir")?; tracing::debug!("copying {wasm_path} to {}", wasm_path_dist.display()); @@ -664,6 +671,7 @@ impl RustApp { &self, origin_path: Utf8PathBuf, destination_path: &Path, + mode: TopLevelMode, ) -> Result<()> { let bytes = fs::read(origin_path) .await @@ -674,7 +682,7 @@ impl RustApp { let mut output: Vec = vec![]; let bytes_clone = bytes.clone(); let session = minify_js::Session::new(); - let res = minify_js::minify(&session, TopLevelMode::Module, &bytes, &mut output); + let res = minify_js::minify(&session, mode, &bytes, &mut output); if res.is_err() { output = bytes_clone; }