Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use string replace in import instead of dynamic module creation #3335

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/wasm-audio-worklet/build.sh
Expand Up @@ -20,3 +20,5 @@ cargo run -p wasm-bindgen-cli -- \
--out-dir . \
--target web \
--split-linked-modules

find snippets/ -name '*.js' -exec sh -c 'for i; do sed -i "s#wbg_es_shim#$(realpath --relative-to="$i" wasm_audio_worklet.js)#g" "$i"; done' "" {} +
45 changes: 0 additions & 45 deletions examples/wasm-audio-worklet/src/dependent_module.rs

This file was deleted.

1 change: 0 additions & 1 deletion examples/wasm-audio-worklet/src/lib.rs
@@ -1,4 +1,3 @@
mod dependent_module;
mod gui;
mod oscillator;
mod wasm_audio;
Expand Down
3 changes: 1 addition & 2 deletions examples/wasm-audio-worklet/src/wasm_audio.rs
@@ -1,4 +1,3 @@
use crate::dependent_module;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsValue;
use wasm_bindgen_futures::JsFuture;
Expand Down Expand Up @@ -53,7 +52,7 @@ pub fn wasm_audio_node(
}

pub async fn prepare_wasm_audio(ctx: &AudioContext) -> Result<(), JsValue> {
let mod_url = dependent_module!("worklet.js")?;
let mod_url = wasm_bindgen::link_to!(module = "/src/worklet.js");
JsFuture::from(ctx.audio_worklet()?.add_module(&mod_url)?).await?;
Ok(())
}
2 changes: 2 additions & 0 deletions examples/wasm-audio-worklet/src/worklet.js
@@ -1,3 +1,5 @@
import init, * as bindgen from 'wbg_es_shim';

registerProcessor("WasmProcessor", class WasmProcessor extends AudioWorkletProcessor {
constructor(options) {
super();
Expand Down