只需要2步:
1. 在package.json 定义 一下 :
{
"name": "my-cli",
...,
"bin": {
"command-name": "./xxx/xxx.js" // 对于package.json 的相对路径
},
...
}
2. 在使用的文件首行写 #!/usr/bin/env node
#!/usr/bin/env node
console.log('test!!!');
只需要2步:
1. 在package.json 定义 一下 :
{
"name": "my-cli",
...,
"bin": {
"command-name": "./xxx/xxx.js" // 对于package.json 的相对路径
},
...
}
2. 在使用的文件首行写 #!/usr/bin/env node
#!/usr/bin/env node
console.log('test!!!');
《怎么写一个带 bin 的 npm 包.doc》
下载本文的Word格式文档,以方便收藏与打印。