Javascript 将 node.js webapp 打包为普通的桌面应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6834537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 23:22:34  来源:igfitidea点击:

Packaging a node.js webapp as a normal desktop app

javascriptmacosnode.jsdesktop-application

提问by Alex Wayne

I've searched a bit but can't find an existing tool for this.

我已经搜索了一点,但找不到用于此的现有工具。

I have a node.js web server that is designed to run on your own computer that does some snazzy things for you. It would be pretty aswesome if I could double click MySnazzyThing.appinstead of installing nodejs, and npm and running node mysnazzyapp.json the command line.

我有一个 node.js web 服务器,它被设计为在你自己的计算机上运行,​​为你做一些时髦的事情。如果我可以双击MySnazzyThing.app而不是安装 nodejs 和 npm 并node mysnazzyapp.js在命令行上运行,那就太棒了。

The .appexecutable would spool up the node server and open a simple native webkit window which would show what would normally be on localhost:3000if I were running on the command line.

.app可执行文件将阀芯了节点服务器,并打开一个简单的本地WebKit的窗口,它会显示一个通常来说是对localhost:3000,如果我在命令行上运行。

This native app could then, say, be distributed through the mac app store. And bam, a node.js desktop app.

比如说,这个本机应用程序可以通过 mac 应用程序商店分发。还有 bam,一个 node.js 桌面应用程序。

Does any such tool exist? Or are there any technical reasons that this wouldn't work as I imagine it?

有没有这样的工具?或者是否有任何技术原因使这无法像我想象的那样工作?

采纳答案by Motin

You can accomplish this using AppJS: https://github.com/appjs/appjs

您可以使用 AppJS 完成此操作:https: //github.com/appjs/appjs

回答by Tracker1

Option 1: electron(aka atom-shell)

选项 1:电子(又名原子壳)

This is the shell that github's Atom editor uses. It's very similar to node-webkit, though it will run the script first, and you have to create a view/window for the user. There are some other minor differences, but it's worth looking at.

这是 github 的 Atom 编辑器使用的 shell。它与 node-webkit 非常相似,尽管它会先运行脚本,并且您必须为用户创建一个视图/窗口。还有一些其他的细微差别,但值得一看。



Option 2: NW.jsformerly node-webkit

选项 2:NW.js以前是 node-webkit

The gist is that it basically extends the JS engine for you to write a web-based app supporting node's extended object model, and modules... you then package your package.json start.html modules and js files into a zip (with the .nw extension) and run it with nw(.exe) .. there are windows, mac and linux builds available.

要点是它基本上扩展了 JS 引擎,让您编写一个基于 Web 的应用程序,支持节点的扩展对象模型和模块……然后将 package.json start.html 模块和 js 文件打包成一个 zip(使用.nw 扩展名)并使用 nw(.exe) 运行它.. 有 windows、mac 和 linux 版本可用。



Option 3: Carlochrom(ium) shell from Node.

选项 3:来自 Node.js 的Carlochrom(ium) shell。

This will allow you to launch the locally installed Chrome as a shell that can connect to a locally running server application. It does require a local chrome, but is very close to what was asked for.

这将允许您将本地安装的 Chrome 作为可以连接到本地运行的服务器应用程序的 shell 启动。它确实需要本地 chrome,但与要求的非常接近。



Option 4: MacGapNode(OSX Only)

选项 4:MacGapNode(仅限 OSX)

MacGap with Node integration (Seems to be getting stale)

MacGap 与 Node 集成(似乎变得陈旧)



Aside: Services...

旁白:服务...

I can't speak for OSX on this as a .App, but it could well be possible to create a background service install in NodeJS and a link to a "local" site on the desktop. Most browsers have an option to not show all the features (I know firefox in particular does).

我不能说 OSX 作为一个 .App,但很有可能在 NodeJS 中创建一个后台服务安装,并在桌面上创建一个“本地”站点的链接。大多数浏览器都可以选择不显示所有功能(我知道 firefox 尤其如此)。

I know your question is to OSX in particular, but in windows you can use NSSM to run anything as a service, and I have used it for NodeJS based services in windows. I think some of the other options above are better depending on your needs though.

我知道您的问题特别是针对 OSX,但在 Windows 中,您可以使用 NSSM 将任何东西作为服务运行,我已经将它用于 Windows 中基于 NodeJS 的服务。我认为上面的一些其他选项更好,具体取决于您的需求。



Removed:

删除:



This answer is copied for multiple questions, these references are mostly for updating convenience.

本回答为多个问题复制,这些参考主要是为了更新方便。

回答by Brian Heese

I suggest looking into Topcube, it's goal is to "Give node developers a way to have a desktop GUI to their node servers using HTML5 + CSS3 as the GUI platform." Topcube at github.

我建议研究 Topcube,它的目标是“为节点开发人员提供一种使用 HTML5 + CSS3 作为 GUI 平台的方式,让他们的节点服务器拥有桌面 GUI。” github上的Topcube

回答by Devin McKeon

Currently there are a plethora of ways to accomplish this.

目前有很多方法可以实现这一点。

The clear winner in the space of packaging a node + html5 app, is currently Electron (used by Atom, VSCode, Slack, Discord, etc).

在打包 node + html5 应用程序的空间中,目前明显的赢家是 Electron(被 Atom、VSCode、Slack、Discord 等使用)。

You can also use any other language packaged as an app (using tools for those languages/stacks), and check for a node installation, launch the "server" script with node, then launch the default browser (or some web view component, by some other means), finally set location to the node service. This is a very light weight and efficient method, however not as well integrated with the OS as a solution like Electron.

您还可以使用打包为应用程序的任何其他语言(使用这些语言/堆栈的工具),并检查节点安装,使用节点启动“服务器”脚本,然后启动默认浏览器(或某些 Web 视图组件,通过其他一些方法),最后将位置设置为节点服务。这是一种非常轻量级和高效的方法,但与操作系统的集成度不如 Electron 之类的解决方案。

The primary competitor to Electron here, is NW.js. As far as I can tell, the main feature that NW.js has that Electron does not (yet) is compilation/obfuscation. While Electron makes auto updates easy.

Electron 的主要竞争对手是 NW.js。据我所知,NW.js 的主要特性是 Electron 没有(还)是编译/混淆。而 Electron 使自动更新变得容易。

https://electron.atom.io/https://nwjs.io/

https://electron.atom.io/ https://nwjs.io/