將您的node.js應用程序打包到一個可執行文件中。
用node-packer編譯任何項目不到5分鐘。
只要它在plain node.js中工作,您就無需在應用程序中修改一行代碼!
視窗,
macos和
Linuxrequire ,包括動態的需求(例如require(myPath + 'module.js' )這是最新的穩定node.js packer版本:
| 作業系統 | 拱。 | 可執行 |
|---|---|---|
| 視窗 | x64 | https://gw.alipayobjects.com/os/enclose-prod/0d0ec8fd-dc9c-4b0a-85df-8bf-8bf4af0e8b8b8d/nodec-v1.5.0-x64.zip |
| macos | x64 | https://gw.alipayobjects.com/os/enclose-prod/bc2022ef-4b88-4c12-9980-39494945c9c198/nodec-v1.5.50-darwin-x64.gz |
| Linux | x64 | https://gw.alipayobjects.com/os/enclose-prod/b6a41a6b5-4542-b777777777-06e4bc292c5e/nodec-v1.5.0-5.0-5.0-50-linux-x64.gz |
每當master Branch CI成功時,Node.js Packer Preeles二進制都會自動生成。這是最新不穩定的預發行構建:
| 作業系統 | 拱。 | 可執行 |
|---|---|---|
| 視窗 | x64 | https://github.com/pmq20/node-packer/releases/download/windows-x64/pre-release-nodec-v140800.121803-x64.exe |
| macos | x64 | https://github.com/pmq20/node-packer/releases/download/darwin-x64/pre-release-nodec-v140800.121803-darwin-x64 |
| Linux | x64 | https://github.com/pmq20/node-packer/releases/download/linux-x64/pre-release-nodec-v140800.121803-linux-x64 |
在Windows上安裝首先安裝先決條件:
然後下載nodec-x64.exe 。
可選地將其放在C:Windows或任何其他PATH目錄下。打開Visual Studio的“ X64本機工具命令提示符”並執行nodec --help 。
在MacOS上安裝首先安裝先決條件:
brew install squashfsCommand Line Tools 。您可以在菜單Xcode -> Preferences -> Downloads下找到它gcc和相關工具鏈,其中包含make然後下載nodec-darwin-x64 。
運行chmod +x以賦予其執行權限並執行./nodec --help 。
根據最近的Travis Build,測試案例將在啟動後不久就會在構建環境為Xcode 11時發生故障。目前,尚不清楚該問題是由Xcode 11引起的還是Travis CI中可能不會影響實際MacOS部署的其他因素。
因此,Travis下的MacOS的構建環境為Xcode 10.2,以確保可以成功執行和完成測試案例。
在Linux上安裝首先安裝先決條件:
sudo yum install squashfs-toolssudo apt-get install squashfs-toolsgcc和g++ 4.9.4或更新,或clang和clang++ 3.4.2或更新然後下載nodec-linux-x64 。
運行chmod +x以賦予其執行權限並執行./nodec --help 。
眾所周知,Red Hat和Centos發行版的默認存儲庫包含非常過時的GCC / G ++(3.8.5),而Ubuntu的最新長期支持(LTS)截至2018年2月15日(Ubuntu 18.04 LTS)包含一個相對更新的GCC / GCC / G ++(7.3.3.0)。
眾所周知,在使用不支持的配置時,彙編可能會失敗,其中先決條件的版本比規定年齡較大。
因此,對於基於紅帽的發行版的用戶來說,在官方存儲店外部安裝GCC / G ++至關重要。對於初學者,可能會看:
此外,眾所周知,從Ubuntu 18.04 LTS編制的二進製文件由於“ GlibCXX_3.4.20'找不到”相關錯誤,因此無法在基於Red Hat 7的發行版(包括Centos)中使用。但是,已知根據我的內部實驗與Ubuntu 18.04 LTS合作的二進製文件。
話雖如此,我仍然建議二進製文件分銷商應為Linux編譯2個版本,其中一個用於Cate for Rhel基於RHEL,而另一個則用於Ubuntu。
根據最近的Travis Build,Linux自NODEC-1.6.0-10.16.0(Node.JS 10.16.0)以來一直無法構建。根本原因尚未確定,最後已知的良好構建是10.15.3,可以在此處下載:https://github.com/slee047/node-packer/releases/releases/tag/1.6.0.3-15.3-1
問題可以在這裡找到:https://github.com/slee047/node-packer/issues/11
注意:此GZ文件(NODEC-DARWIN-X64.GZ)包含NODEC的過時版本(NODEC 1.5.0,帶有Node.js 8.3.0)。原始維護者未指定如何將此存儲庫構建到單個可執行文件中,因此,只能直接在源代碼上運行較新的版本。
nodec [OPTION]... [ENTRANCE]
--current Uses the current Node.js release
--lts Uses the LTS Node.js release
-r, --root=DIR Specifies the path to the root of the application
--output=FILE Specifies the path of the output file
-d, --tmpdir=DIR Specifies the directory for temporary files
--clean-tmpdir Cleans all temporary files that were generated last time
--keep-tmpdir Keeps all temporary files that were generated last time
--make-args=ARGS Passes extra arguments to make
--vcbuild-args=ARGS Passes extra arguments to vcbuild.bat
-n, --npm=FILE Specifies the path of npm
--skip-npm-install Skips the npm install process
--debug Enables debug mode
-o, --dest-os=OS Specifies the destination operating system (enum: win mac solaris freebsd openbsd linux android aix)
-a, --dest-arch=ARCH Specifies the destination CPU architecture (enum: arm arm64 ia32 mips mipsel ppc ppc64 x32 x64 x86 s390 s390x)
--quiet Enables quiet mode
-v, --version Prints the version of nodec and exit
-h, --help Prints this help and exit
注意:如果未提供入口,將產生單個RAW NODE.JS解釋器可執行文件。
注意:要在64位計算機上編譯到32位Windows OS兼容程序,請使用X64 X32交叉編譯環境。安裝Visual Studio後,您應該能夠在開始菜單中找到它。另外,您必須使用32位node.js,因為通過node -pe process.arch檢測到拱門信息。
git clone --depth 1 https://github.com/jashkenas/coffeescript.git
cd coffeescript
nodec bin/coffee
./a.out (or a.exe on Windows)
git clone --depth 1 https://github.com/eggjs/examples.git
cd examples/helloworld
npm install
nodec node_modules/egg-bin/bin/egg-bin.js
./a.out dev (or a.exe dev on Windows)
| 專案 | 差異 |
|---|---|
| PKG | pkg被黑客入侵fs.* API的動態性是為了訪問包裝文件,而Node.js Packer將它們獨自一人離開,而是通過libsquash在更深層次的水平上工作。 PKG使用JSON存儲包裝文件,而Node.js Packer則使用更複雜且廣泛使用的壁球作為其數據結構。 |
| enclosejs | enclosejs將對包裝文件的訪問限制為僅五個fs.* api,而node.js packer支持所有fs.* api。 enclosejs是專有的許可,並在Node.js Packer獲得MIT許可時使用時收取錢,並且用戶都可以免費使用並免費修改它。 |
| nexe | Nexe由於使用browserify而不支持動態require ,而Node.js Packer支持各種require.resolve require |
| 阿薩爾 | ASAR將代碼存檔和可執行文件保留在Node.js Packer時將所有JavaScript源代碼與Node.js Virtual Machine鏈接在一起,並生成單個可執行文件作為最終產品。 ASAR使用JSON來存儲文件的信息,而Node.js Packer則使用sequhfs。 |
| 附屬 | Appimage僅支持Linux支持壁球的內核,而Node.js Packer支持Linux,MacOS和Windows的所有三個平台,同時沒有內核的任何特殊功能要求。 |
nodec還支持交叉兼容。由於Node.js是由來源構建的,因此您需要正確設置工具鏈,以獲取有效的編譯器來為目標平台生產二進製文件。
您可以使用Crosstool-NG或您喜歡的任何其他工具輕鬆地做到這一點。
完成有效工具鏈的構建後(如果使用Crosstool-ng,默認情況下,請啟用C ++),您將能夠正確編譯。只需設置您的環境,就可以知道使用跨編譯工具鏈而不是系統的默認構建工具。
一個示例(您可能需要調整值或指定其他變量):
export AR="x86_64-unknown-linux-gnu-ar"
export CC="x86_64-unknown-linux-gnu-gcc"
export CXX="x86_64-unknown-linux-gnu-g++"
export LINK="x86_64-unknown-linux-gnu-g++"
export CPP="x86_64-unknown-linux-gnu-gcc -E"
export LD="x86_64-unknown-linux-gnu-ld"
export AS="x86_64-unknown-linux-gnu-as"
export CCLD="ax86_64-unknown-linux-gnu-gcc ${TARGET_ARCH}"
export NM="x86_64-unknown-linux-gnu-nm"
export STRIP="x86_64-unknown-linux-gnu-strip"
export OBJCOPY="x86_64-unknown-linux-gnu-objcopy"
export RANLIB="x86_64-unknown-linux-gnu-ranlib"
export F77="x86_64-unknown-linux-gnu-g77 ${TARGET_ARCH}"
unset LIBC
#Define flags
#export CXXFLAGS="-march=armv7-a"
export LDFLAGS="-L${CSTOOLS_LIB} -Wl,-rpath-link,${CSTOOLS_LIB} -Wl,-O1 -Wl,--hash-style=gnu"
export CFLAGS="-isystem${CSTOOLS_INC} -fexpensive-optimizations -frename-registers -fomit-frame-pointer -O2 -ggdb3"
export CPPFLAGS="-isystem${CSTOOLS_INC}"
# export CCFLAGS="-march=armv7-a"
#Tools
export CSTOOLS=/Volumes/crosstools/x86_64-unknown-linux-gnu
export CSTOOLS_INC=${CSTOOLS}/include
export CSTOOLS_LIB=${CSTOOLS}/lib
#export ARM_TARGET_LIB=$CSTOOLS_LIB
# export GYP_DEFINES="armv7=1"
#Define other things, those are not 'must' to have defined but we added
export SHELL="/bin/bash"
export TERM="screen"
export LANG="en_US.UTF-8"
export MAKE="make"
#Export the path for your system
#export HOME="/home/gioyik" #Change this one with the name of your user directory
export PATH=${CSTOOLS}/bin:/usr/arm-linux-gnueabi/bin/:$PATH
Minqi Pan等。
麻省理工學院