hudada-cli
Version:
专为程序员准备的本地文档搜索,快捷开发工具
170 lines (134 loc) • 2.84 kB
Markdown
- 主版本号.次版本号.修订号(Major.Minor.Patch)
- 例如:`2.4.1`
```json
{
"dependencies": {
"package1": "1.0.0", // 精确版本
"package2": "~1.2.3", // 允许修订号更新(1.2.3 到 1.2.9)
"package3": "^1.2.3", // 允许次版本和修订号更新(1.2.3 到 1.9.9)
"package4": "*", // 最新版本
"package5": ">=1.2.3", // 大于等于指定版本
"package6": "1.2.x", // x 位置任意值
"package7": "1.x.x" // 同 ^1.0.0
}
}
```
- 项目运行时必需的依赖
```json
{
"dependencies": {
"express": "^4.17.1",
"react": "^17.0.2"
}
}
```
- 仅开发时需要的依赖
```json
{
"devDependencies": {
"jest": "^27.0.6",
"eslint": "^7.32.0"
}
}
```
- 插件对宿主包的依赖声明
```json
{
"peerDependencies": {
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
}
}
```
- 可选依赖,安装失败不影响整体
```json
{
"optionalDependencies": {
"image-optimizer": "^1.0.0"
}
}
```
- 锁定依赖树的具体版本
- 确保团队成员使用相同版本
- 加快安装速度
- 类似 package-lock.json
- 会被发布到 npm 仓库
- 适用于需要发布的库
```bash
npm outdated
npm ls
npm view [package] versions
```
```bash
npm update
npm update [package]
npm install [package]@[version]
```
```bash
npm config set registry https://your-private-registry.com
npm install -g nrm
nrm ls
nrm use taobao
```
```bash
npm config set @your-scope:registry https://your-registry.com
```
```bash
npm audit
npm audit fix
npm audit fix --force
```
```bash
npm prune
rm -rf node_modules
npm install
npm cache clean --force
```
1. 版本锁定
- 使用 package-lock.json
- 重要依赖使用确切版本号
2. 依赖分类
- 正确使用不同类型的依赖声明
- 避免将开发依赖放入 dependencies
3. 定期更新
- 定期检查和更新依赖
- 关注安全公告
4. 依赖审查
- 安装前检查包的大小和依赖树
- 使用 `npm why` 检查依赖原因