trunk-rs / trunk

Build, bundle & ship your Rust WASM application to the web.
https://trunkrs.dev/
Apache License 2.0
3.53k stars 255 forks source link

`build` doesn't work but `serve` does #268

Closed UltiRequiem closed 3 years ago

UltiRequiem commented 3 years ago

Steps to reproduce:

Clone and cd: https://github.com/UltiRequiem/rust-webassembly-counter-yew

Build will end succesfully, but if you visit the build: image

However, if I serve the files insted with , e.g live-server, it works: image

The dist dir also doesn't work on github pages: https://ultirequiem.github.io/rust-webassembly-counter-yew/

edward-shen commented 3 years ago

Build will end succesfully, but if you visit the build

This isn't an error that trunk can resolve (nor really an error to begin with). This is the browser having a restricted policy on what it type of resources it can request and from where; I'll defer specific examples to the error message that you posted.

The dist dir also doesn't work on github pages

The failure on Github pages is because you're trying to access a resource that doesn't exist. If you actually go to the js file the browser is trying to load, you'll see it's actually GitHub returning a 404. This is because GH pages are formatted as <username>.github,io/repo_name/<path> rather than <username>.github.io/<path>. If you try manually load the correct location, you'll see that it'll load the correct file.

For the first, there is absolutely no solution for external (read: non-inlined) wasm files other than to use a HTTP server to actually serve the content. For the second, you can just edit where the generated HTML is asking to get. Support for automatically doing this would be blocked on being able to rewrite the output directory on render, which is semi-related to #267.

UltiRequiem commented 3 years ago

So I can't deploy things that require wasm on ghpages?

edward-shen commented 3 years ago

You can, you just need to edit the html that trunk generates to point to the correct location.

UltiRequiem commented 3 years ago

Thanks, for those who come later, this is what I did:

https://github.com/UltiRequiem/rust-webassembly-counter-yew/commit/6a80e49387fc812aeba0a39a734501beb5e472c1

s2terminal commented 2 years ago

I think that using the --public-url option would work. For example, trunk build --release --public-url rust-webassembly-counter-yew.

https://trunkrs.dev/assets/#directives