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

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

问题描述

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

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.

我更喜欢单个可执行文件,例如Windows 上的 .exe 文件.

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

我该如何解决这个问题?

How could I approach this?

我知道这个线程,无论如何这只是关于 Windows.我怎样才能以独立于平台的方式实现这一目标?有任何想法吗?最佳实践?...?

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? ...?

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

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.

哦,重要的是:我不想对源代码进行任何更改,因此使用相对路径调用 require 应该仍然有效,即使这样相对路径现在位于打包的应用程序中.

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.

有什么想法吗?

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

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

推荐答案

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

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.

这是理想解决方案的次佳选择.

It's the next best thing to an ideal solution.

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

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