Integrating with create-react-app #3
Comments
I managed to get it working by adding the // through this file we can override the default cra configuration
// see: https://github.com/timarney/react-app-rewired
const path = require('path')
module.exports = function override(config, env) {
const wasmExtensionRegExp = /\.wasm$/;
config.resolve.extensions.push('.wasm');
// make the file loader ignore wasm files
const fileLoader = config.module.rules
.find(rule => rule.loader && rule.loader.endsWith(`${path.sep}file-loader${path.sep}index.js`));
fileLoader.exclude.push(wasmExtensionRegExp);
// and add a dedicated loader for them
config.module.rules.push({
test: wasmExtensionRegExp,
include: path.resolve(__dirname, "src"),
use: [{loader: require.resolve('wasm-loader'), options: {}}]
});
return config;
} Now I'm hitting another issue (Chrome 59):
This seems to be unrelated to the loader, so resolving this issue. |
@cimi I'm having this error:
Any ideas? |
Sounds like a corrupted module. It could happen because of a number of different reasons.
Upload your file there to test whether or not the file is actually valid to begin with. |
I spent forever looking or a solution to this, so hoping this saves someone some time. New version of CRA seems to have rearranged the file-loader rule. My hack is: // through this file we can override the default cra configuration
// see: https://github.com/timarney/react-app-rewired
const path = require('path');
module.exports = function override(config, env) {
const wasmExtensionRegExp = /\.wasm$/;
config.resolve.extensions.push('.wasm');
// make the file loader ignore wasm files
let fileLoader = null;
config.module.rules.forEach(rule => {
(rule.oneOf || []).map(oneOf => {
if (oneOf.loader && oneOf.loader.indexOf('file-loader') >= 0) {
fileLoader = oneOf;
}
});
});
fileLoader.exclude.push(wasmExtensionRegExp);
// Add a dedicated loader for them
config.module.rules.push({
test: wasmExtensionRegExp,
include: path.resolve(__dirname, 'src'),
use: [{ loader: require.resolve('wasm-loader'), options: {} }],
});
return config;
}; Note: that needs to go into "start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test --env=jsdom", I read a bit that CRA 2+ can do this, so unsure if react-app-rewired is strictly necessary? For building WASM that can be consumed, easiest way is to use wasm-pack, which will create a "dependencies": {
"native": "file:../native/pkg",
} Finally, this must be async loaded, so my // The wasm must load async. Just wait to load anything else until it's done.
async function loadNative() {
await import('native');
await import('./app');
}
loadNative(); |
This blog post might be helpful for future visitors (using @AThilenius' answer above!): https://prestonrichey.com/blog/react-rust-wasm/ |
I encountered with
I am following @prichey 's solution |
seems this is related to version issue of |
Note for future people @AThilenius : As of 4/15/20 this solution still works. Here is a complete code example. |
I'm trying to use
wasm-loader
with create-react-app and I'm having some trouble getting it to work.I'm using react-app-rewired to override the configuration:
I've tried several different variants of this, got the same result for all of them (instead of
use
, referenceloader
directly, have an object withloader
andoptions
insideuse
, omitinclude
).The registration seems to work fine, and checking the output from the rules it seems that the rule for
wasm-loader
is added correctly:However, when trying to load wasm files I get not found failures:
Any idea what might be the issue?
Thanks for building this by the way, I can see it being really useful!
The text was updated successfully, but these errors were encountered: