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
Webpack/esbuild/bundler support or examples. #1948
Comments
I'm not sure why napi-rs generates the code it does, instead of maybe a try/catch, or a loop over candidate files. I can work on a PR if either of those sound good. It would benefit me if the code could be tree shook and platform/arch could be overwritten so I can create a bundle from a mac that will run on linux and have the big |
Sounds good to me :) It would also be good if this code could be using both commonjs and esmodule. ESM support would help a lot with tree shaking. |
@everett1992 I'll add some examples in the next week |
I think your example only works because argon2 has separate artifact packages (@node-rs/argon2-linux-x64-gnu) and napi-rs skips the existsSync for those packages.
My issue occurs in a package that only has inline .node files. |
I suggest that if you want to adapt to the bundler scenario, you should separate binaries for different platforms and publish them as separate npm packages, just like @node-rs/argon2. I responded in your PR, if you take into account the scenario of inline .node files, then some other tools such as |
I'll forward that to the maintainers of the package I'm using :) |
Webpack, esbuild, or other bundlers are somtimes used outside a browser context, for example packaging for Lambda.
I couldn't find any examples of using a napi-rs library with webpack or esbuild and my initial attempts to use webpack's node-loader or esbuild's copy loader did not work due to the module resolution code generated by napi-rs
Both bundlers correctly replaced this line with the file path from their bundle
But they did not replace
localFileExisted
because it does not use require or import.In both webpack and esbuild the existsSync check would fail because the bundled code included a hash in the file path or relocated the file. I was able to get esbuild working with the following options
The text was updated successfully, but these errors were encountered: