搜索文档
1# 新建并进入dormant-cli文件夹 2mkdir dormant-cli && cd dormant-cli 3 4# 快速初始化一个npm项目 5npm init -y
在根目录下创建 bin/index.js 文件作为入口文件,并添加如下代码
bin/index.js
1. 2├─ bin 3│ └─ index.js 4└─ package.json
1#!/usr/bin/env node 2console.log('我是dormant-cli脚手架');
:::
package.json
bin
1{ 2 "name": "dormant-cli", 3 "version": "1.0.0", 4 "description": "", 5 "main": "index.js", 6 "bin": "/bin/index.js", // [!code error] 7 "bin": { // [!code warning] 8 "dormant-cli": "/bin/index.js", // [!code warning] 9 }, // [!code warning] 10 "scripts": { 11 "test": "echo \"Error: no test specified\" && exit 1" 12 }, 13 "keywords": [], 14 "author": "", 15 "license": "ISC" 16}
npm link
dormant-cli
1dormant-cli ❯ npm link 2 3added 1 package in 468ms
这里的 dormant-cli 是指 package.json 中 name 字段的值。
name
1dormant-cli ❯ dormant-cli 2我是dormain-cli脚手架
当我们在控制台看到 我是dormain-cli脚手架 这一信息时,标志着项目已成功初始化!
我是dormain-cli脚手架