How to compile NPM modules to binaries for all platforms

浪尽此生 提交于 2021-02-11 14:30:57

问题


how to convert NODE MODULES into binaries to support all platform.

  • Windows x86
  • Windows X64
  • Linux
  • OS X

and load those binaries in Node application instead of npm modules. ?


回答1:


A good starting point might be to take a look at http://cylonjs.com/blog/2014/11/19/creating-multiplatform-precompiled-binaries-for-node-modules/

It would help if you could clarify your question, since I'm not sure exactly what you are trying to achieve. I answered on the assumption that you have binaries you want to include for node modules on multiple platforms (see link above). Otherwise, just having node modules installed as part of an application should be the same as adding them as a dependency in the package.json.




回答2:


i want to convert those modules into pre compiled binaries and then load those binaries in my node application

Two questions here: 1) How to convert Node.js modules written in JavaScript into binaries executable on your platform and 2) How to use such compiled binary executables as part of your Node.JS application.

A great answer to question 1) is a tool called Zeit PKG at: https://github.com/zeit/pkg

I have used Zeit PKG to compile my Node.js application into a Windows-10 executable, and it works. Zeit PKG has options to target other platforms like Linux as well but I haven't tested that.

I would like to learn the answer to the 2nd question myself, (how) can an .exe -file (with some restrictions and/or wrapping) be used as a module in a Node.js application?



来源:https://stackoverflow.com/questions/34293032/how-to-compile-npm-modules-to-binaries-for-all-platforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!