package.json 配置
{
"name": "@scope/package-name",
"version": "1.0.0",
"description": "项目的详细描述信息",
"keywords": ["react", "vue", "frontend", "ui"],
"homepage": "https://example.com",
"bugs": {
"url": "https://github.com/user/repo/issues",
"email": "support@example.com"
},
"license": "MIT",
"author": {
"name": "作者姓名",
"email": "author@example.com",
"url": "https://author-website.com"
},
"contributors": [
{
"name": "贡献者1",
"email": "contributor1@example.com"
}
],
"maintainers": [
{
"name": "维护者1",
"email": "maintainer1@example.com"
}
],
"main": "lib/index.js",
"module": "es/index.js",
"browser": "dist/index.umd.js",
"types": "lib/index.d.ts",
"typings": "lib/index.d.ts",
"exports": {
".": {
"import": "./es/index.js",
"require": "./lib/index.js",
"browser": "./dist/index.umd.js"
},
"./package.json": "./package.json"
},
"files": [
"lib",
"es",
"dist",
"src",
"README.md",
"LICENSE"
],
"directories": {
"lib": "./lib",
"bin": "./bin",
"man": "./man",
"doc": "./docs",
"example": "./examples",
"test": "./test"
},
"bin": {
"my-cli": "./bin/cli.js"
},
"man": "./man/my-package.1",
"private": true,
"publishConfig": {
"registry": "https://npm.example.com",
"access": "public"
},
"workspaces": [
"packages/*",
"apps/*"
],
"type": "module",
"scripts": {
"dev": "vite",
"serve": "vite preview",
"build": "vite build",
"build:dev": "vite build --mode development",
"build:prod": "vite build --mode production",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue",
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx,.vue --fix",
"format": "prettier --write .",
"type-check": "tsc --noEmit",
"docs": "jsdoc -d docs src/",
"clean": "rimraf dist lib es",
"prepare": "husky install",
"prepublishOnly": "npm run build",
"postinstall": "echo 'Installation complete'",
"precommit": "lint-staged",
"release": "standard-version",
"deploy": "gh-pages -d dist"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vue": "^3.3.0",
"axios": "^1.4.0",
"lodash": "^4.17.21",
"moment": "^2.29.0",
"classnames": "^2.3.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"@types/react": "^18.2.0",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"@vitejs/plugin-react": "^4.0.0",
"@vitejs/plugin-vue": "^4.0.0",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-react": "^7.32.0",
"eslint-plugin-vue": "^9.15.0",
"husky": "^8.0.3",
"jest": "^29.5.0",
"lint-staged": "^13.2.0",
"prettier": "^2.8.8",
"typescript": "^5.1.0",
"vite": "^4.3.0",
"vitest": "^0.32.0"
},
"peerDependencies": {
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
},
"peerDependenciesMeta": {
"react": {
"optional": true
}
},
"optionalDependencies": {
"fsevents": "^2.3.0"
},
"bundledDependencies": [
"lodash"
],
"overrides": {
"semver": "^7.0.0"
},
"resolutions": {
"lodash": "^4.17.21"
},
"engines": {
"node": ">=16.0.0",
"npm": ">=8.0.0",
"yarn": ">=1.22.0"
},
"os": ["linux", "darwin", "win32"],
"cpu": ["x64", "arm64"],
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie 11"
],
"repository": {
"type": "git",
"url": "https://github.com/user/repo.git",
"directory": "packages/my-package"
},
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/username"
},
{
"type": "opencollective",
"url": "https://opencollective.com/project"
}
],
"eslintConfig": {
"extends": ["@vue/typescript/recommended", "prettier"],
"rules": {
"no-console": "warn"
}
},
"prettier": {
"semi": true,
"singleQuote": true,
"tabWidth": 2
},
"stylelint": {
"extends": ["stylelint-config-standard"]
},
"jest": {
"testEnvironment": "jsdom",
"setupFilesAfterEnv": ["<rootDir>/src/setupTests.js"]
},
"babel": {
"presets": ["@babel/preset-env", "@babel/preset-react"]
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx,vue}": ["eslint --fix", "prettier --write"],
"*.{css,scss,less}": ["stylelint --fix", "prettier --write"],
"*.{md,json}": ["prettier --write"]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"commitlint": {
"extends": ["@commitlint/config-conventional"]
},
"sideEffects": false,
"unpkg": "dist/index.umd.js",
"jsdelivr": "dist/index.umd.js",
"esnext": "src/index.js",
"config": {
"port": 3000,
"theme": "dark"
},
"volta": {
"node": "18.16.0",
"npm": "9.5.1"
},
"packageManager": "npm@9.5.1"
}
版本号规则说明
语义化版本格式
MAJOR.MINOR.PATCH (如: 1.2.3)
- MAJOR: 不兼容的API修改
- MINOR: 向后兼容的功能新增
- PATCH: 向后兼容的问题修正
版本范围符号
^1.2.3: 兼容版本,允许 >=1.2.3 <2.0.0
~1.2.3: 合理版本,允许 >=1.2.3 <1.3.0
1.2.3: 精确版本,固定版本号
>=1.2.3: 大于等于指定版本
<1.2.3: 小于指定版本
1.2.x: 通配符,匹配 1.2.*
*: 任意版本
latest: 最新版本
alpha/beta/rc: 预发布版本
字段优先级和重要性
🔴 必需字段
name: 包名称(发布时必需)
version: 版本号(发布时必需)
🟡 重要字段
description: 包描述
main/module/browser: 入口文件
scripts: 脚本命令
dependencies: 生产依赖
devDependencies: 开发依赖
🟢 推荐字段
keywords: 搜索关键词
author: 作者信息
license: 许可证
repository: 代码仓库
engines: 环境要求
⚪ 可选字段
homepage: 项目主页
bugs: 问题反馈
funding: 资金支持
- 各种工具配置字段