Is it possible to run a command from a bin
script in a package.json
? I know it expects a path to file and trying to run a command there results in an error upon installation (after publishing to npm). Is it possible to run a command like it is in an npm start
?
Examples:
{
"name": "myscript",
"version": "1.0.3",
"bin": {
"myscript": "app/main.js"
}
}
This will create a symlink from the app/main.js
script to /usr/local/bin/myscript
Instead, this is what I want to achieve:
{
"name": "myscript",
"version": "1.0.3",
"bin": {
"myscript": "echo hello world"
}
}
Possible workarounds are also appreciated.
Based on what you've written, it seems like you are looking for https://docs.npmjs.com/cli/run-script .
With the package.json
script property, you can define scripts as arbitrary shell commands or programs installed into the ./node_modules/.bin
.
您是否尝试过运行npm link
https://docs.npmjs.com/cli/link这将创建指向您的二进制文件的链接,然后您可以在命令行上以myscript
运行您的脚本。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.