hudada-cli
Version:
专为程序员准备的本地文档搜索,快捷开发工具
134 lines (106 loc) • 2.25 kB
Markdown
```json
{
"scripts": {
"start": "node index.js",
"test": "jest",
"build": "webpack",
"dev": "nodemon index.js"
}
}
```
- pre和post钩子
- 例如: preinstall, postinstall
```json
{
"scripts": {
"preinstall": "echo '安装前执行'",
"install": "echo '安装中'",
"postinstall": "echo '安装后执行'"
}
}
```
用于管理多包项目(monorepo):
```json
{
"name": "root-project",
"workspaces": [
"packages/*"
]
}
```
```ini
registry=https://registry.npmmirror.com/
save-exact=true
package-lock=false
```
- 通过 .env 文件管理环境变量
- 使用 cross-env 跨平台设置环境变量
- package-lock.json 的重要性
- npm shrinkwrap 命令
```json
{
"dependencies": {
"exact": "1.0.0", // 精确版本
"patch": "~1.0.0", // 补丁版本更新
"minor": "^1.0.0", // 次要版本更新
"latest": "*", // 最新版本
"git": "git+https://github.com/user/project.git",
"local": "file:../local-package"
}
}
```
常用命令:
```bash
npm config get cache
npm cache clean --force
npm cache verify
```
```bash
npm audit
npm audit fix
npm audit --json
```
1. 注册 npm 账号
2. 登录: `npm login`
3. 发布: `npm publish`
```bash
npm version patch
npm version minor
npm version major
```
```bash
npm config set registry http://your-private-registry.com
npm config set @your-scope:registry http://your-private-registry.com
```
- `npm ci`: 用于 CI/CD 环境,严格按照 package-lock.json 安装
- 特点:
- 更快的安装速度
- 确保可重现的构建
- 自动删除 node_modules