将您的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等。
麻省理工学院