Skip to content

Conversation

ealmloff
Copy link
Member

If any wasm bindgen assets include links to external assets, the swc bundler fails to process them. This PR adds a CLI argument to skip the SWC bundler with wasm bindgen assets and instead hash and optimize the whole folder. The regression test added in the playwright folder has an example of a project that requires this flag. If you use a raw module link in wasm-bindgen and bundle your js asset separately, the swc bundler fails to read the link as a file:

#[used]
static BINDINGS_JS: Asset = asset!(
    "/assets/bindings.js",
    AssetOptions::js().with_hash_suffix(false)
);

#[wasm_bindgen(raw_module = "/assets/bindings.js")]
extern "C" {
    #[wasm_bindgen]
    pub type Foo;
    #[wasm_bindgen(constructor)]
    pub fn new() -> Foo;
}

Most bundlers include an option to exclude specific files from the bundling process for external assets, but it looks like swcpack does not support that feature. The SWC bundler is also deprecated and will be removed in the next release so we should start thinking about a migration plan. There is a separate issue discussing other bundlers here: #4449

Fixes #4440

@ealmloff ealmloff requested a review from a team as a code owner July 21, 2025 16:29
@ealmloff ealmloff added bug Something isn't working web relating to the web renderer for dioxus cli Related to the dioxus-cli program labels Jul 21, 2025
@jkelleyrtp
Copy link
Member

jkelleyrtp commented Jul 22, 2025

Is SWC just failing here because we're not copying the referenced assets over? Maybe we could customize the path loader config argument to use the crate's root as a fallback.

I'm not a huge fan of adding a CLI arg to work around a bug rather than fixing the underlying issue itself, if we can.

@ealmloff
Copy link
Member Author

This is an issue with the swc bundler not being flexible enough for some use cases which isn't easy to fix without changing swc itself. SWC is deprecated so I don't think we should spend too much time working around issues like this. I made the fallback automatic which doesn't require a new flag, but it does mean the js optimization happens serially before instead of parelell with the other asset optimization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cli Related to the dioxus-cli program web relating to the web renderer for dioxus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dx serve --release fails to include dioxus-internal JS scripts in certain cases where wasm-bindgen is used

2 participants