-
-
Notifications
You must be signed in to change notification settings - Fork 27k
@next react-scripts(webpack.config.js) to resolve .wasm
extension?
#4912
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
Comments
I don't think it was left out or removed intentionally. @Timer do you see any reason not to resolve |
I dunno, are we supporting wasm yet? We need tests before we turn it on. |
@pd4d10 It doesn't seem that just adding I've been trying to implement this in #6049 but am having some issues. Async ImportIt seems that wasm modules need to be imported asynchronously. This makes sense because the recommended way to load a WASM module is async (WebAssembly.instantiateStreaming). I'm not sure how to make a jest transformer which requires being imported with an async ImportsThe second argument to InterfaceI'm kinda confused about the interface which should be exposed. When you do
What |
Hmm, it seems WASM will have some kind of esmodules support in the future, but it doesn’t yet. WebAssembly/proposals#12 For now we should probably just use wasm-loader. What do you think @iansu ? Should we wait for esmodules + wasm or use wasm loader now with some kind of experimental wasm extension (‘.wasm.expirmental’)? |
Yeah, it's weird. I got wasm support working in dev and build though react-app-rewired with this change: module.exports = function override(config, env) {
config.resolve.extensions.push(".wasm");
config.module.rules.forEach(rule => {
(rule.oneOf || []).forEach(oneOf => {
if (oneOf.loader && oneOf.loader.indexOf("file-loader") >= 0) {
// Make file-loader ignore WASM files
oneOf.exclude.push(/\.wasm$/);
}
});
});
return config;
}; But then importing is really strange. You need to use the async import syntax at some point, and it won't work if you don't. But where you import is kind of up to you, as long as the wasm file is a transitive dependency of your async imported code. At that point, the imported wasm file acts as a WebAssembly.Instance that's been instantiated with the exports of the module it was imported in. This was all pretty unintuitive to me, but maybe I just expected less magic? The code I was trying to run was rust built with wasm-pack, so even though I don't understand why it works it seems like webpack and wasm-pack both agree on the es modules format at least. The trouble with using wasm-loader is that it would break code that expects it to work this way. There aren't a lot of wasm packages on npm, but they've got to standardize on an expected loader at some point. I honestly am not an expert here, but it seems like the ecosystem is moving quick, so committing to a specific wasm loader now might be premature? Even though I really want this! |
It's tricky using Wasm in Webpack, @surma from Google created an interesting example: I managed to get it working, but I Is it interesting for Create React App project? I can make a Pull Request. |
@shayc You can hold off on making a PR; I really think we should wait for some stabilization in the library ecosystem since by and large people won't be writing their own wasm, they'll be importing it from npm. Today the rust toolchain makes code that's pretty webpack friendly, but I think that go and llvm emit wasm directly and expect you to call I might be wrong though! I'm going to take some time this weekend to do a survey of the current state of things. |
Ok, I did some reading and my opinion is pretty much the same; hold off for a while until this stabilizes more. The most relevant info I could find is the WASM ES module proposal and it's only stage 2. Until then, users can use the imperative js apis with their wasm files saved in |
Any updates on this? |
See #7911. |
Looks like ejecting is the only way to use wasm with cra. Thanks. |
Is there no way of making it work by overriding config in config-overrides? |
From what I have seen in other discussions, it seems like the create-react-app philosophy is to ignore the fact that it uses webpack internally - in other words, webpack features should not be relied upon. However, webpack includes a match for For example, when using a
So it would be nice if create-create-react app could disable this default rule in webpack so users can handle As a workaround, I changed the file extension of the |
@dlech what would people do without people like you ;) thank you! |
Regarding the application for react-app-rewired, since the oneOf rules now have multiple loaders, this seems to work better to exclude wasm from the file loader.
|
I was curious if there was any reason
.wasm
extension was left out fromresolve.extensions
list?Webpack also default to include
.wasm
.It'd be nice to start using/experimenting wasm from create-react-app!
The text was updated successfully, but these errors were encountered: