我的个人博客

本地使用的常用npm命令

Published on
Published on
/1 mins read/---

链接包以在本地使用

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中使用Typescriptesbuild开发CLI的常用package.json配置

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...

愉快地链接!