Ais*_*war 113 javascript windows exe node.js
我有一个我写的节点应用程序,我运行如下:
node.exe app.js inputArg
有什么方法可以将它自己打包成.exe吗?所以我可以做这样的事情?
App.exe inputArg
我有一些方法可以通过使用批处理文件来伪造这个,所以我可以这样做:
App.bat inputArg
但这需要我在该文件夹中拥有所有依赖项和节点,这并不理想.
Cla*_*ick 50
我使用的解决方案是Roger Wang的node-webkit.
这是打包nodejs应用程序并分发它们的绝佳方式,它甚至可以让您选择将整个应用程序"捆绑"为单个可执行文件.它支持windows,mac和linux.
以下是有关部署node-webkit应用程序的各种选项的一些文档,但简而言之,您执行以下操作:
就像一个补充说明 - 我已经使用它发运了几个生产盒/安装CD应用程序,并且它运行良好.相同的应用程序在Windows,Mac,Linux和Web上运行.
Ric*_*asi 31
有一些替代品,包括免费和商业.我没有使用它们,但理论上它们应该工作:
大多数将要求您将批处理文件保留为主可执行文件,然后捆绑node.exe和您的脚本.
根据您的脚本,您还可以选择将其移植到JSDB,它支持通过简单地向其添加资源来创建可执行文件的简单方法.
第三个准解决方案是将节点保存在某处C:\utils
,并将此文件夹添加到您的PATH
环境变量中.然后你可以在那个运行节点+你喜欢的脚本的目录中创建.bat文件 - 我让coffeescript coffee
以这种方式在windows 上工作.可以使用批处理文件,vb脚本或安装程序自动执行此设置.
sok*_*kie 28
jos*_*736 21
默认情况下,Windows将.js
文件与Windows脚本宿主(Microsoft的独立JS运行时引擎)相关联.如果在命令提示符下键入script.js(或双击.js
资源管理器中的文件),则执行脚本wscript.exe
.
这可能是使用全局设置解决本地问题,但您可以改为关联 .js
文件node.exe
,以便在命令提示符下键入script.js或双击/拖动项目到脚本将使用Node启动它们.
当然,如果像我一样 - 你.js
用编辑器关联文件,以便双击它们打开你最喜欢的文本编辑器,这个建议将没有多大帮助.您还可以向.js
文件添加 "Execute with Node" 的右键单击菜单项,尽管此替代方案无法解决您的命令行需求.
最简单的解决方案可能就是使用批处理文件 - 您不必在脚本所在的文件夹中包含Node的副本.只需完全引用Node可执行文件:
"C:\Program Files (x86)\nodejs\node.exe" app.js %*
Run Code Online (Sandbox Code Playgroud)
另一种选择是这个非常简单的C#应用程序,它将使用自己的文件名+ .js
作为要运行的脚本启动Node ,并传递任何命令行参数.
class Program
{
static void Main(string[] args)
{
var info = System.Diagnostics.Process.GetCurrentProcess();
var proc = new System.Diagnostics.ProcessStartInfo(@"C:\Program Files (x86)\nodejs\node.exe", "\"" + info.ProcessName + ".js\" " + String.Join(" ", args));
proc.UseShellExecute = false;
System.Diagnostics.Process.Start(proc);
}
}
Run Code Online (Sandbox Code Playgroud)
因此,如果您将生成的EXE命名为"app.exe",则可以键入,app arg1 ...
并使用命令行启动Node "app.js" arg1 ...
.请注意,C#bootstrapper应用程序将立即退出,让Node负责控制台窗口.
由于这可能是相对广泛的兴趣,我继续在GitHub上提供这个,包括编译的exe如果与陌生人进入货车是你的事情.
bit*_*fed 12
由于这个问题已得到解答,因此推出了另一种解决方案.
https://github.com/appjs/appjs
在撰写本文时,这是通过编译成可执行文件的精简铬包打包node.js应用程序的最终解决方案.
编辑:AppJS不再处于活动状态,但本身建议使用名为deskshell的fork.
https://github.com/sihorton/appjs-deskshell/
Nep*_*oxx 11
这里有很多好的答案,但它们并不像JXcore那么简单.
一旦在Windows上安装了JXcore,您只需运行:
jx package app.js "myAppName" -native
Run Code Online (Sandbox Code Playgroud)
这将生成一个可以分发的.exe文件,并且可以在没有任何外部依赖性的情况下执行(您甚至不需要系统上的JXcore或Node.js).
以下是该功能的文档:http://jxcore.com/packaging-code-protection/#cat-74
编辑2018
该项目现在已经死了但它仍然在这里托管:https://github.com/jxcore/jxcore-release(感谢@Elmue)
Har*_*ono 11
我正在使用以下技术:
让我们做如下:
npm i -g @vercel/ncc
ncc build app.ts -o dist (我的入口文件是app.ts,输出在dist文件夹中,确保你在package.json和app.ts所在的文件夹中运行,上面运行后你可能会看到index.js文件在文件夹 dist 中)
npm install -g pkg(安装pkg)
pkg index.js(确保您位于上面的 dist 文件夹中)
Try disclose
: https://github.com/pmq20/disclose
disclose
essentially makes a self-extracting exe out of your Node.js project and Node.js interpreter with the following characteristics,
Try node-compiler
: https://github.com/pmq20/node-compiler
I have made a new project called node-compiler
to compile your Node.js project into one single executable.
It is better than disclose
in that it never runs slowly for the first time, since your source code is compiled together with Node.js interpreter, just like the standard Node.js libraries.
Additionally, it redirect file and directory requests transparently to the memory instead of to the file system at runtime. So that no source code is required to run the compiled product.
How it works: https://speakerdeck.com/pmq20/node-dot-js-compiler-compiling-your-node-dot-js-application-into-a-single-executable
Comparing with Similar Projects,
pkg(https://github.com/zeit/pkg): Pkg hacked fs.* API's dynamically in order to access in-package files, whereas Node.js Compiler leaves them alone and instead works on a deeper level via libsquash. Pkg uses JSON to store in-package files while Node.js Compiler uses the more sophisticated and widely used SquashFS as its data structure.
EncloseJS(http://enclosejs.com/): EncloseJS restricts access to in-package files to only five fs.* API's, whereas Node.js Compiler supports all fs.* API's. EncloseJS is proprietary licensed and charges money when used while Node.js Compiler is MIT-licensed and users are both free to use it and free to modify it.
Nexe(https://github.com/nexe/nexe): Nexe does not support dynamic require because of its use of browserify, whereas Node.js Compiler supports all kinds of require including require.resolve.
asar(https://github.com/electron/asar): Asar uses JSON to store files' information while Node.js Compiler uses SquashFS. Asar keeps the code archive and the executable separate while Node.js Compiler links all JavaScript source code together with the Node.js virtual machine and generates a single executable as the final product.
AppImage(http://appimage.org/):AppImage仅支持具有支持SquashFS内核的Linux,而Node.js编译器支持Linux,macOS和Windows的所有三个平台,同时对该内核没有任何特殊功能的要求。
目前,我认为要走的路是deno
这是
deno compile mainProgram.js
Run Code Online (Sandbox Code Playgroud)
现有的节点项目可能需要某种转换,至少对于 require 语句(将节点项目转换为 deno)
归档时间: |
|
查看次数: |
122356 次 |
最近记录: |