如何将Node.js应用程序部署为单个可执行文件? [英] How do I deploy Node.js applications as a single executable file?

查看:114
本文介绍了如何将Node.js应用程序部署为单个可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已经编写了一个Node.js应用程序,现在我想分发它。当然,我想让用户容易,所以我不希望他安装Node.js,运行 npm install 然后手动输入 node app.js



我最喜欢的是单个可执行文件,例如



如何处理?



我知道此线程,无论如何这是只关于Windows。如何以平台无关的方式实现这一点?有任何想法吗?最佳做法? ...?



完美的解决方案是一个编译器,我可以给源文件夹。源文件夹包含各种 .js 文件, node_modules 文件夹和一些元数据(例如的package.json 。输出应该是各种平台的二进制文件,例如Windows,OS X和Linux。



哦,重要的是:我不想让任何对源代码的更改,所以调用需要与相对路径应该仍然可以工作,即使这个相对路径现在在打包的应用程序。



任何想法?



PS:我不希望用户独立安装Node.js,应该包含在可执行文件中

解决方案

同时我找到了(为我)完美的解决方案: nexe ,它从Node.js应用程序(包括其所有模块)创建一个可执行文件。



虽然目前它有一些缺点(不在Windows上运行,不支持二进制模块),但这是理想解决方案的最佳选择。


Supposed I have written a Node.js application, and I now would like to distribute it. Of course, I want to make it easy for the user, hence I do not want him to install Node.js, run npm install and then manually type node app.js.

What I'd prefer was a single executable file, e.g. an .exe file on Windows.

How could I approach this?

I am aware of this thread, anyway this is only about Windows. How could I achieve this in a platform-independent manner? Any ideas? Best practices? ...?

The perfect solution was a "compiler" I can give a source folder to. The source folder contains the app itself in various .js files, the node_modules folder and some metadata, such as the package.json. The output should be binaries for various platforms, such as Windows, OS X and Linux.

Oh, and what's important: I do not want to make any changes to the source code, so calls to require with relative paths should still work, even if this relative path is now inside the packaged app.

Any ideas?

PS: I do not want the user to install Node.js independently, it should be included inside the executable as well.

解决方案

Meanwhile I have found the (for me) perfect solution: nexe, which creates a single executable from a Node.js application including all of its modules.

Although at the moment it has some disadvantages (does not run on Windows and does not support binary modules), it's the next best thing to an ideal solution.

这篇关于如何将Node.js应用程序部署为单个可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆