[英]Running package.json scripts of external libraries JS
I have a created library that has a script called "versionator": "node app.js"
inside package.json.我创建了一个库,它在 package.json 中有一个名为
"versionator": "node app.js"
。 But currently, other projects that download this library can only use it by importing the module as:但是目前,其他下载这个库的项目只能通过导入模块来使用它:
const versionator = require("versionator")
versionator()
Is there a way that i can run the script called "versionator" that is inside my library folder from another projects that download this lib?有没有一种方法可以让我从另一个下载这个库的项目运行我的库文件夹中名为“versionator”的脚本?
repo: https://github.com/sousadiego11/versionator-js回购: https://github.com/sousadiego11/versionator-js
What you need is to specify a bin
object inside your package.json您需要在 package.json 中指定一个
bin
object
https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bin https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bin
{
"bin": {
"versionator": "./app.js"
}
}
This will create a bin called versionator.这将创建一个名为 versionator 的 bin。
Edit:编辑:
As CherryDT pointed out in his comment you can call it then via正如 CherryDT 在他的评论中指出的那样,您可以通过
npx versionator
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.