-
Notifications
You must be signed in to change notification settings - Fork 14
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
How to load onigasm.wasm via webpack #2
Comments
My original vision was to have it loaded through await loadWASM(require('file-loader!onigasm/lib/onigasm.wasm')) But please, I beg you, to show me the alternative method(asm loader). I won't think twice if some other method makes the developer experience more smoother. |
I'm actually not that familiar with webpack, I just know the bare minimum to make it work in theia, so I can try the file-loader and see if it works for now 😄 |
Actually I'm getting
using
Let me tinker a bit more with wasm and webpack... |
Totally agree and pissed at the fact that I can't find a way myself to disable Webpack 4's WASM parser. The problem is whenever Webpack 4 encounters a The culprit in question - webpack/lib/wasm/WebAssemblyModulesPlugin.js I have tried I am sticking to Webpack 3 for now, until the WASM dust settles a bit. ( |
It's critical to note that Webpack 4 supports importing import('./add.wasm').then(({ add }) => {
console.log(add(22, 2200))
}) Example above will work out of the box when compiled with Webpack 4. Now you might ask, then why can we not import Please read Background section of this comment to see the complexity. |
Thank you for the in-depth explanation. So from what I understand is that we're stuck with using webpack3 for now. Although I'd usually be fine with it, we've been using webpack4 for a while so I should check to make sure it doesn't break anything else. Otherwise it's a bummer for us :( Indeed it looks like noParse option not working is probably a bug in webpack (I saw that you opened an issue for that), hopefully something can be done about this. |
I'll strongly advise you to continue using Webpack 4. While webpack issue is being fixed, use PS: Since Webpack 4 now resolves |
Fixed in 6787446 and available in Let me know if you got through the day using |
Thanks! I'll report back as soon as I test this out. |
Please ignore all the methods we've discovered so far (most of which are ugly hacks), thanks to Florent and Tobias comment, there's a better way and we get to stay with Webpack 4 😘 // index.js
import {
loadWASM,
OnigRegExp
} from 'onigasm'
(async () => {
await loadWASM(require('onigasm/lib/onigasm.wasm'))
const reg = new OnigRegExp('[a-z]+')
console.log(reg.searchSync('nice'))
})() // webpack.config.js
module.exports = {
mode: 'development',
entry: __dirname + '/index.js',
output: {
filename: 'bundle.js',
publicPath: 'dist/'
},
module: {
rules: [{
test: /\.wasm$/,
loader: "file-loader",
type: "javascript/auto",
}]
}
} |
This works fine with me. We can close the issue if you consider this okay :) |
@NeekSandhu @epatpol This method doesn't work for me. I got this from Using its |
If I recall correctly there was a change in the file-loader module a couple of months back that introduced that changed behaviour in order to support the es module „import“ statement. |
I was able to use:
// wiring from webpack `encoded-uint8array-loader` to inline WASM buffer view
declare module '*.wasm' { const bytes: Uint8Array; export = bytes; } |
@zm-cttae Where do you put the I get the "Cannot find module 'onigasm.wasm' or its corresponding type declarations." error on the |
Hi you need to make a |
Thanks for your suggestions. With a However, I'm still missing something. Webpack can't find the |
You can import it using a relative import where |
Perfect, that seems to get me to the next step. So far: import * as bytes from '../node_modules/onigasm/lib/onigasm.wasm'
// ...
await loadWASM(bytes); With the following Webpack config:
This compiles but but gives me the following error in the browser: |
I think the issue is that you got a EDIT its the |
What's the best way to do it? Usually I would load it with an asm loader for webpack and then use the script from the assembly file, but now I only have to supply it to
loadWASM
which comes fromonigasm
, any ideas on how to do this? ThanksThe text was updated successfully, but these errors were encountered: