怎么写一个带 bin 的 npm 包

只需要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!!!');

 

posted @ 2019-08-19 13:24  张啊咩  阅读(1011)  评论(0编辑  收藏  举报