[英]node js application bundling for macOS
我開發了一個節點js應用程序。 我已經設法使用在 Windows 上完美運行的node pkg將我的應用程序捆綁到一個 .exe 文件中。 現在我需要為 macOS 做同樣的事情,以便我的應用程序可以在 Apple 計算機上運行。 node pkg本身也為 Linux 和 macOS 提供了可執行文件,但我無法使用 macOS 版本。 有沒有什么方法可以用 node js 為 macOS 開發軟件? 如果 macOS 有哪些文件格式與 Windows 中的 .exe 文件類似?
使用pkg打包 Node.js 應用程序時,默認情況下會創建適用於 Windows、Linux 和 macOS 的可執行文件。
這個最小的例子創建了一個可執行文件,將“HELLO WORLD”打印到控制台:
$ echo "console.log('HELLO WORLD')" > index.js
$ npx pkg index.js
npx: installed 138 in 5.155s
> pkg@4.4.2
> Targets not specified. Assuming:
node10-linux-x64, node10-macos-x64, node10-win-x64
這會產生以下可執行文件:
$ ls -l
total 227360
-rwxr-xr-x 1 pahund 110015913 39698697 Dec 24 14:03 index-linux
-rwxr-xr-x 1 pahund 110015913 40712141 Dec 24 14:03 index-macos
-rw-r--r-- 1 pahund 110015913 35979810 Dec 24 14:03 index-win.exe
在 macOS 終端中,您可以通過文件訪問設置rwxr-xr-x
判斷index-linux
和index-macos
是可執行的(這就是“x”的意思)。
以.exe
結尾的文件特定於 Windows,在 Linux 和 macOS 中不使用。 這並不意味着index-linux
和index-macos
不可執行。
您可以像任何其他二進制文件或腳本一樣從終端運行它們:
$ ./index-macos
HELLO WORLD
(請注意,在終端中運行時,路徑./
是必需的)
您也可以在 macOS Finder 中找到index-macos
並雙擊它,這將打開一個打印“HELLO WORLD”的終端窗口。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.