链接包以在本地使用
cd ~/path/to/package
npm link
取消链接包
cd ~/path/to/package
npm unlink
从全局npm列表中移除
npm rm --global <package-name>
检查包是否已移除
npm list --global
清除npx
缓存
rm -rf ~/.npm/_npx
执行包而不全局安装
npx <package-name>
# 添加@latest确保使用最新版本
npx <package-name>@latest
在NodeJS中使用Typescript和esbuild开发CLI的常用package.json
配置
// ...
"scripts": {
"dev": "tsc -w && npm run link",
"start": "node dist/index.js",
"build": "esbuild src/index.ts --bundle --platform=node --target=node18 --outfile=dist/index.js",
"up": "npm run build && npm publish --access public && npm run unlink",
"link": "npm unlink your-cli && npm i -g && chmod +x ./dist/index.js && npm link your-cli",
"unlink": "npm rm -g your-cli && npm unlink your-cli"
},
"bin": {
"your-cli": "./dist/index.js"
}
// more configs...
愉快地链接!