如何将nodejs编译成一个完全静态的二进制文件

时间:2022-06-06 00:42:11

Does anyone know how to statically compile nodejs to a single executable binary? I means no share libraries needed.

有人知道如何静态地将nodejs编译成一个可执行的二进制文件吗?我的意思是不需要共享库。

There are some guides for old version nodejs, but not work for last one.

有一些旧版本的nodejs的指南,但不是最后一个。

Thanks!

谢谢!

5 个解决方案

#1


2  

For those who still find this topic relevant there is a project called node-packer, that compiles javascript code along with the nodejs binary available here https://github.com/pmq20/node-packer but in order to have a truly static build one needs to modify the ruby script and add the flags --fully-static and --without-npm which should enable the binary to run without libstdc++ or glibc, but there are some caveats as explained on the nodejs wiki. I have also already made the modification here (https://github.com/cmosh/node-packer), just append the flag --static to the command, i.e nodec --static foo.js. Also in order to run this you will need to install both ruby and nodejs and run nodec script within the bin folder of the cloned repo.

对于那些仍然觉得这个主题相关的有一个项目叫node-packer,随着nodejs将javascript代码编译二进制可用这里https://github.com/pmq20/node-packer但为了有一个真正的静态构建一个需要修改ruby脚本,添加的标志——全静态和without-npm应该启用二进制运行没有libstdc + +或glibc,但也有一些警告nodejs wiki作为解释。我已经在这里做了修改(https://github.com/cmosh/node-packer),只是在命令I后面添加了标记——静态的。e nodec——静态foo.js。为了运行这个,您需要安装ruby和nodejs,并在克隆的repo的bin文件夹中运行nodec脚本。

#2


1  

Actually, I want a single static binary to run on android platform.

实际上,我希望在android平台上运行一个单一的静态二进制文件。

And now , up to version 0.11.8, node.js officially add android support.

现在,到0。11。8版本,node。js正式加入android支持。

my colleague build it not only arm, but also android-x86. everything works fine!

我的同事不仅构建了arm,还构建了android-x86。一切工作正常!

https://github.com/joyent/node/commit/5e4e8ec429381a8d1eebe31647e9daaaae42c54b

https://github.com/joyent/node/commit/5e4e8ec429381a8d1eebe31647e9daaaae42c54b

#3


1  

You can use nodejs-static docker image to get statically compiled Node.JS binary linked with musl libc.

您可以使用nodejs-static docker映像来获得静态编译的节点。与musl libc链接的JS二进制文件。

https://hub.docker.com/r/dundee/nodejs-static/

https://hub.docker.com/r/dundee/nodejs-static/

#4


0  

Meanwhile there is http://enclosejs.com/ which seems to be able to generate a single binary.

同时还有http://enclosejs.com/,它似乎可以生成一个二进制文件。

#5


0  

Here's another one that can package your application in a single executable https://www.npmjs.com/package/pkg

这是另一个可以在单个可执行的https://www.npmjs.com/package/pkg中打包应用程序的程序

#1


2  

For those who still find this topic relevant there is a project called node-packer, that compiles javascript code along with the nodejs binary available here https://github.com/pmq20/node-packer but in order to have a truly static build one needs to modify the ruby script and add the flags --fully-static and --without-npm which should enable the binary to run without libstdc++ or glibc, but there are some caveats as explained on the nodejs wiki. I have also already made the modification here (https://github.com/cmosh/node-packer), just append the flag --static to the command, i.e nodec --static foo.js. Also in order to run this you will need to install both ruby and nodejs and run nodec script within the bin folder of the cloned repo.

对于那些仍然觉得这个主题相关的有一个项目叫node-packer,随着nodejs将javascript代码编译二进制可用这里https://github.com/pmq20/node-packer但为了有一个真正的静态构建一个需要修改ruby脚本,添加的标志——全静态和without-npm应该启用二进制运行没有libstdc + +或glibc,但也有一些警告nodejs wiki作为解释。我已经在这里做了修改(https://github.com/cmosh/node-packer),只是在命令I后面添加了标记——静态的。e nodec——静态foo.js。为了运行这个,您需要安装ruby和nodejs,并在克隆的repo的bin文件夹中运行nodec脚本。

#2


1  

Actually, I want a single static binary to run on android platform.

实际上,我希望在android平台上运行一个单一的静态二进制文件。

And now , up to version 0.11.8, node.js officially add android support.

现在,到0。11。8版本,node。js正式加入android支持。

my colleague build it not only arm, but also android-x86. everything works fine!

我的同事不仅构建了arm,还构建了android-x86。一切工作正常!

https://github.com/joyent/node/commit/5e4e8ec429381a8d1eebe31647e9daaaae42c54b

https://github.com/joyent/node/commit/5e4e8ec429381a8d1eebe31647e9daaaae42c54b

#3


1  

You can use nodejs-static docker image to get statically compiled Node.JS binary linked with musl libc.

您可以使用nodejs-static docker映像来获得静态编译的节点。与musl libc链接的JS二进制文件。

https://hub.docker.com/r/dundee/nodejs-static/

https://hub.docker.com/r/dundee/nodejs-static/

#4


0  

Meanwhile there is http://enclosejs.com/ which seems to be able to generate a single binary.

同时还有http://enclosejs.com/,它似乎可以生成一个二进制文件。

#5


0  

Here's another one that can package your application in a single executable https://www.npmjs.com/package/pkg

这是另一个可以在单个可执行的https://www.npmjs.com/package/pkg中打包应用程序的程序