I've just started to play around with this https://github.com/thomashorrobin/create-react-app-rust create-react-app fork that adds rust support. I had some problems with typescript using it and decide to rebase on top of the latest create-react-app to not waste time debugging for something that's already fixed here. While doing this I realised that the actual changes for rust seem minimal. I'm not sure if there was ever a discussion about folding this fork into this project. I couldn't find anything in the issues to that extent.
My question is: would it be of interest to include Rust (via WASM) support in this package directly, or maintain the separate fork? If there's interest I can rebase again and prepare the fork to be submitted as a PR. Thanks!
Hi @bowd!
Does the rust support require changes to the react-scripts or other internal tools or does it just change the scaffolding and add the relevant dependencies and build scripts?
No major changes as far as I can see what we're looking at is just some webpack loaders, some build script changes and scaffolding. I would modify the scaffolding to work similarly to the --typescript flag and the build based on detecting the Cargo.toml file. I will need to understand the changes made in that fork better and make sure I agree with all of them, and add tests of course.
Not to co-opt this thread but for posterity, I wrote about a solution to this using react-app-rewired: https://prestonrichey.com/blog/react-rust-wasm/. Obviously vanilla CRA support for Wasm would be great but this might be a resource for others playing around in this space in the meantime.
@prichey I've tried your way but I get this:
../webassembly-tests-rust/pkg/webassembly_tests_rust_bg.wasm
Module parse failed: Unexpected section: 0xfe
You may need an appropriate loader to handle this file type.
Error: Unexpected section: 0xfe
Any advice? I found this issue https://github.com/webpack/webpack/issues/8781 but I have no way to upgrade webpack, I think.
@ponchofiesta Did you set your wasm-bindgen version as specified here? https://github.com/rustwasm/book/issues/148#issuecomment-463809784
Now it works. Great solution!
I get the same error message, even with explicitly setting wasm-bindgen version :( At the same time, ejecting the CRA would cause a flurry of other different problems, so I guess I need to wait until there is a more 'mainstream' option for rust->wasm->CRA
keep up the good work guys!
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.
I'm really not sure is a good fit for CRA. Note that this is different than #4912, which is just asking for wasm support, whereas this is using rust-native-wasm-loader to have webpack actually compile rust code into wasm. IMO that's pretty niche.
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.
FYI: https://prestonrichey.com/blog/react-rust-wasm/ works out-of-the-box with wasm-bindgen 0.2.58
Most helpful comment
Not to co-opt this thread but for posterity, I wrote about a solution to this using react-app-rewired: https://prestonrichey.com/blog/react-rust-wasm/. Obviously vanilla CRA support for Wasm would be great but this might be a resource for others playing around in this space in the meantime.