怎么写一个带 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!!!');
原文地址:https://www.cnblogs.com/amiezhang/p/11376575.html