是否可以编译一个 JS 应用程序 + NodeJS 解释器转换为单个可执行文件?
是否可以将 JS 应用程序和 NodeJS 解释器编译成单个可执行文件以进行分发?
Is it possible to compile a JS application and the NodeJS interpreter into a single executable for distribution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你需要一个带有 git 和 python 的 linux 盒子,然后是丑陋的解决方案:
you need a linux box with git and python, then ugly solution:
这听起来似乎很明显,但这是我的看法。
“用于分发的单个可执行文件”听起来很像安装程序...
安装程序将包含或能够在线获取您的 js 脚本和编译后的 Node.js。它将解压所有内容并在 /etc/init.d/ 中创建一个脚本来启动和停止服务器。
如果您的所有客户端都在同一个发行版(例如 Debian)上,我只需为适当的打包工具(例如 apt)制作一个包,然后让打包工具处理所有事情。
如果客户端都有不同的发行版,您可以查看 autopackage。
This might sound obvious, but here's my take on it.
A "single executable for distribution" sounds a lot like an installer...
An installer would contain or be able to fetch online your js scripts and a compiled node.js. It would unpack everything and create a script in /etc/init.d/ to start and stop the server.
If all your clients are on the same distro (e.g. Debian), I'd just make a package for the appropriate packaging tool (e.g. apt) and let the package tool handle everything.
It the clients all have different distros, you could look into autopackage.
如果您的目标是执行 javascript,您也许可以创建一个简单的 C 或 C++ 包装程序,它会生成一个解释器并评估您的 JS。如果您想要单个文件,则可以将 js 源作为字符串常量包含在内。
当您编译包装器程序时,您需要静态链接它到节点和其余部分它的依赖树。静态链接不是依赖于系统上的共享库,而是将项目依赖的例程复制到编译后的二进制文件中。
如何执行此操作取决于您的环境
If your goal is to execute javascript, you might be able to create a simple C or C++ wrapper program which would spawn an interpreter and evaluate your JS. If you want a single file, the js source could be included as a string constant.
When you compiled the wrapper program, you'd want to statically link it to node and the rest of its dependency tree. Rather than depending on shared libraries on the system, static linking will copy the routines your project depends on into the compiled binary.
How you do this will depend on your environment