macos 将 Node.js 应用程序打包为 OS X 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11003211/
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-10-21 09:14:47  来源:igfitidea点击:

Package a Node.js application as an OS X application

javascriptmacosnode.js

提问by luisgo

I want to build an interface for a series of terminal commands that our developers use to manage their development environments. I'd like to try to build it in Node.js.

我想为我们的开发人员用来管理他们的开发环境的一系列终端命令构建一个接口。我想尝试在 Node.js 中构建它。

Now, I'm thinking I can create it as an HTML5/CSS 3/JavaScript application using Express.js, etc... and then would like to package it as a native OS X application. Meaning, an application that I can just send them, they double click on and run, but that either launches a Chrome browser and navigates to the localhost:port server that hits the script or simply starts the server and instructs the user to go to the URL. Either way is fine.

现在,我想我可以使用Express.js等将它创建为 HTML5/CSS 3/JavaScript 应用程序,然后想将其打包为原生 OS X 应用程序。意思是,我可以发送一个应用程序,他们双击并运行,但是要么启动 Chrome 浏览器并导航到命中脚本的 localhost:port 服务器,要么只是启动服务器并指示用户转到网址。无论哪种方式都很好。

I am doing this because I need access to the local system to be able to configure a number of things and interact with any number of running (headless VMs). So I can't simply serve this from a server and have them visit the site.

我这样做是因为我需要访问本地系统才能配置许多东西并与任意数量的运行(无头虚拟机)交互。所以我不能简单地从服务器提供它并让他们访问该站点。

Any ideas?

有任何想法吗?

回答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 CoolAJ86

Here's a screencast + writeup on the subject of an installer (.pkg):

这是关于安装程序 (.pkg) 主题的截屏视频 + 文章:

How to create an OS X pkg for NodeJS apps

如何为 NodeJS 应用程序创建 OS X pkg

As for the .app, I'm not sure yet, but I'm hot on the trail.

至于 .app,我还不确定,但我很感兴趣。

Also:

还:

回答by Martin Cleaver

Check out http://github.com/rogerwang/node-webkit- its a project sponsored by Intel to package up Node.js apps for the desktop

查看http://github.com/rogerwang/node-webkit- 它是英特尔赞助的一个项目,用于为桌面打包 Node.js 应用程序

Specifically, see http://strongloop.com/strongblog/creating-desktop-applications-with-node-webkit/

具体见http://strongloop.com/strongblog/creating-desktop-applications-with-node-webkit/

回答by Motin

Check out AppJS: http://appjs.com/- "Build Desktop Applications for Linux, Windows and Mac using HTML, CSS and Javascript"

查看 AppJS:http://appjs.com/ - “使用 HTML、CSS 和 Javascript 为 Linux、Windows 和 Mac 构建桌面应用程序”

Sounds like a good match :)

听起来很匹配:)

回答by TheHippo

If you compile node.jsfrom source every JavaScript file from nodes libfolder will be included into the binary. That same way could pack your code into the binary.

如果node.js从源代码编译,则节点lib文件夹中的每个 JavaScript 文件都将包含在二进制文件中。同样的方式可以将您的代码打包到二进制文件中。

I am not familar how Mac OSX packages are created, but at the end it does not seem to be very hard. Just pack your custom node binary into one.

我不熟悉 Mac OSX 包是如何创建的,但最后似乎并不。只需将您的自定义节点二进制文件打包成一个。