Open jb55 opened 2 years ago
I tried including in a vite.js project via installing from NPM and I get the following error after importing:
yes this is the problem, it can only be used in a vanilla-js context atm
Let me know if there is anything I can do to help with getting this working with JS bundlers. At a bare minimum I can help test as I have a PWA I am working on currently, but if there are some next steps that you have in mind, feel free to hit me up!
On Thu, Jul 21, 2022 at 10:12:43PM -0700, Aaron wrote:
Let me know if there is anything I can do to help with getting this working with JS bundlers. At a bare minimum I can help test as I have a PWA I am working on currently, but if there are some next steps that you have in mind, feel free to hit me up!
unless there's an easy way to package emscripten wasm builds into webpack... I might have to just create a pure js version of lnsocket...
I think that in most modern bundlers like Webpack and Vite you can directly import wasm files. So maybe the wasm could be compiled without the "glue" js code and then a small module could be written that interfaces with the wasm file? Then for the lnsocket package you could import the wasm file as well as the javascript module, load up the wasm and then init the js file passing the initialised wasm file to it?
I found some links that might be useful: https://stackoverflow.com/questions/45295339/can-i-somehow-build-webassembly-code-without-the-emscripten-glue
I don't have any experience using emscripten and others, but i'll do some more digging. Hopefully writing a pure js version can be avoided.
I have it working in a Svelte PWA now as is by loading it in via script tag which works pretty well. For some reason I couldn't get it to work that way in a Sveltekit project 🤷♂️
For anyone else looking for a solution for use in Webpack, Vite, Rollup projects, you can check out a JS version of lnsocket that I have created for easy integration with web browser bundles.
Webpack does static analysis on the emscripten module and complains when it sees nodejs 'require' statements, even if they are never called in practice.
It also breaks when trying to pack the wasm module. If we get a local webpack build working and distribute that to npm, then lnsocket should work out of the box for React projects.