将 Node.js 编译成可执行文件而不将整个 Node.js 放入其中

Compiling Node.js into an executeable without putting the entirety of Node.js in there

所以,我正在尝试将一个简单的 hello world 脚本打包成一个可执行文件,但在使用 pkg or nexe, it looks like the entirety of Node.js get's packed in there, as they are way bigger than they need to be (around 30 MB). I did stumble upon EncloseJS, however, it was last updated in 2017 and no longer works (and the owner themself advices you to switch to pkg) 时。

那么,还有其他比这更好的编译器吗?

提前致谢!

此外:这是一个极其复杂的脚本,需要 运行

console.log("Whosebug is amazing!");
setTimeout(() => {
   process.exit(0);
}, 2000);

以及我本地安装的版本:

NPM Node
6.14.12 14.16.1

不,pkgnexe 是这样工作的——它们将您的代码和 NodeJS 融合在一个可执行文件中。因为,基本上,您需要 NodeJS 到 运行 nodejs 脚本 - 有一些特定的方法,例如 fs,例如, 在常规 js 中不存在。

总之,此时有一些项目可以查看:

  1. NectarJS - 实际开发状态的项目,基本上是将 JS 编译成 C。但是他们的主要目标非常有趣。

  2. 有一个叫做QuickJS的小型JS引擎将JS编译成C

  3. 另一种选择是ts2c 将JS翻译成C,但是没有 支持很多功能。

但请记住,它们中没有一个与 pkg 一样好用, 完全支持最新的 JS 功能和所有 NodeJS 方法。