是否可以编译一个 JS 应用程序 + NodeJS 解释器转换为单个可执行文件?

发布于 2024-09-16 07:49:59 字数 48 浏览 3 评论 0原文

是否可以将 JS 应用程序和 NodeJS 解释器编译成单个可执行文件以进行分发?

Is it possible to compile a JS application and the NodeJS interpreter into a single executable for distribution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一曲爱恨情仇 2024-09-23 07:49:59

你需要一个带有 git 和 python 的 linux 盒子,然后是丑陋的解决方案:

$ git clone git://github.com/ry/node.git
$ cd node
$ vim src/node.js    # add your code to end before "process.loop();"
$ ./configure
$ make
$ sudo make install
$ node

you need a linux box with git and python, then ugly solution:

$ git clone git://github.com/ry/node.git
$ cd node
$ vim src/node.js    # add your code to end before "process.loop();"
$ ./configure
$ make
$ sudo make install
$ node
北座城市 2024-09-23 07:49:59

是否可以将 JS 应用程序和 NodeJS 解释器编译成单个可执行文件进行分发?

这听起来似乎很明显,但这是我的看法。

“用于分发的单个可执行文件”听起来很像安装程序...

安装程序将包含或能够在线获取您的 js 脚本和编译后的 Node.js。它将解压所有内容并在 /etc/init.d/ 中创建一个脚本来启动和停止服务器。

如果您的所有客户端都在同一个发行版(例如 Debian)上,我只需为适当的打包工具(例如 apt)制作一个包,然后让打包工具处理所有事情。

如果客户端都有不同的发行版,您可以查看 autopackage

Is it possible to compile a JS application and the NodeJS interpreter into a single executable for distribution?

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.

笑着哭最痛 2024-09-23 07:49:59

如果您的目标是执行 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文