gpt4 book ai didi

node.js - 发布到 npmjs.com 时分发带有 nodejs 模块的二进制可执行文件

转载 作者:行者123 更新时间:2023-12-02 02:10:55 26 4
gpt4 key购买 nike

我有一个可执行文件 myutil.exe,我从我的 nodejs 模块调用它来执行一些功能。我希望将它打包,将我的 NodeJS 模块发布到 npmjs.com,并且在这个 Windows 平台上使用时,可执行文件应该是这个 nodejs 库的一部分,因为我的 nodejs 代码调用可执行文件来执行一个功能。我已经从 nodejs 运行了这个命令行二进制文件。

如何做到这一点以及如何最好地将这个可执行二进制文件包含在其中?它应该以某种方式托管在包之外吗?

另请注意,这只是一个限制,此时它必须是 Windows 上的可执行文件,或者由于其中代码的性质,它必须是 Linux 系统上的可运行二进制文件,不能是 DLL/库。稍后也许我可以将它的一些代码移动到 DLL/库中。

最佳答案

supply a bin field in your package.json which is a map of command name to local file name. On install, npm will symlink that file into prefix/bin for global installs, or ./node_modules/.bin/ for local installs.

例如,如果您在 package.json 中有这个,并在全局安装了您的包,则命令 npmputty 将在 PATH 中可用。

"bin": {
"npmputty": "./bin/putty.exe"
},

如果你不想在包中发布这个可执行文件,可以实现 postinstall script从 github.com 之类的地方下载它。

{
"scripts" : {
"postinstall" : "scripts/download_from_github.js"
}
}

关于node.js - 发布到 npmjs.com 时分发带有 nodejs 模块的二进制可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67766855/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com