前言:package.json 里的字段大致分两部分,一部分标准字段,一部分非标字段。标准字段就是官方定义好的字段,非标字段包括作者自定义字段
1. 标准字段
1.1 name
包名,就是我们用 npm 去下载的名字,就定义在这。
{ "name": "yqcoder-admin-ts" }
1.2 version
版本,当前包的版本号
{ "version": "0.0.0" }
1.3 description
描述,描述这个包的主要用途
{ "description": "this is a system" }
1.4 main
入口文件,指定这个包的入口文件,如果不设置默认包根目录的 index.js 文件
{ "main": "index.js" }
1.5 files
指定包开发完成后上传到 npm 的文件。
{ "files": ["index.js", "dist"] }
1.6 repository
包上传后的仓库信息
{ "repository": { "type": "git", "url": "xxxx/xx/xxx.git", "directory": "packages/xxx" } }
1.7 keywords
npm 上的搜索关键字
{ "keywords": ["admin"] }
1.8 author
包作者
{ "author": "Yqcoder" }
1.9 license
提供开源许可类型
{ "license": "MIT" }
1.10 bugs
提交 issues 地址
{ "bugs": "https://github.com/xxx/xxx" }
1.11 homepage
展示一些官网首页
{ "homepage": "https://github.com/xxxx" }
1.12 dependencies
生产环境下需要用到的依赖
{ "dependencies": { "@amap/amap-jsapi-loader": "^1.0.1" } }
1.13 devDependencies
开发阶段时需要的依赖包,不需要在生产中使用
{ "devDependencies": { "sass": "^1.70.0" } }
1.14 scripts
终端脚本语言
{ "scripts": { "dev": "vite", "build": "vue-tsc && vite build", "preview": "vite preview" } }
2. 非标字段
2.1 module
给构建工具看的,在使用构建工具的情况下,去导入一个包,特别是使用 ESM 模块方法的时候,会把 module 设置的文件给你
{ "module": "dist/xxxx.esm-bundler.js" }
2.2 types
给 ts 看的,整个包的类型定义文件
{ "types": "dist/xxx.d.ts" }
2.3 unpkg
给 cdn 看的,有些用户导入包的时候会使用 CDN,在用这种方式导入的时候,CDN 会从 npm 上去下载相应的文件,从哪里下载?就从这个文件路径下载。
{ "unpkg": "dist/xxx.global.js" }
2.4 jsdelivr
给 cdn 看的
{ "jsdelivr": "dist/xxx.global.js" }
2.5 exports
给构架工具看的,在构建工具的环境中,你在导入包的时候有很多方式。
{ "exports": { ".": { "types": "./dist/xxxx.d.ts" }, "./*": "./*" } }
2.6 sideEffects
给构建工具看的,标识下包有没有副作用
{ "sideEffects": false }
2.7 buildOptions
作者自定义,提供一些 rollup 的打包信息的。
{ "buildOptions": { "name": "xxxx", "formats": ["esm-bunder"] } }
3. vue 中的 package.json 文件
{ "name": "vue", "version": "2.7.16", "packageManager": "pnpm@8.9.2", "description": "Reactive, component-oriented view layer for modern web interfaces.", "main": "dist/vue.runtime.common.js", "module": "dist/vue.runtime.esm.js", "unpkg": "dist/vue.js", "jsdelivr": "dist/vue.js", "typings": "types/index.d.ts", "files": [ "src", "dist/*.js", "dist/*.mjs", "types/*.d.ts", "compiler-sfc", "packages/compiler-sfc" ], "exports": { ".": { "types": "./types/index.d.ts", "import": { "node": "./dist/vue.runtime.mjs", "default": "./dist/vue.runtime.esm.js" }, "require": "./dist/vue.runtime.common.js" }, "./compiler-sfc": { "types": "./compiler-sfc/index.d.ts", "import": "./compiler-sfc/index.mjs", "require": "./compiler-sfc/index.js" }, "./dist/*": "./dist/*", "./types/*": ["./types/*.d.ts", "./types/*"], "./package.json": "./package.json" }, "sideEffects": false, "scripts": { "dev": "rollup -w -c scripts/config.js --environment TARGET:full-dev", "dev:cjs": "rollup -w -c scripts/config.js --environment TARGET:runtime-cjs-dev", "dev:esm": "rollup -w -c scripts/config.js --environment TARGET:runtime-esm", "dev:ssr": "rollup -w -c scripts/config.js --environment TARGET:server-renderer", "dev:compiler": "rollup -w -c scripts/config.js --environment TARGET:compiler ", "build": "node scripts/build.js", "build:ssr": "npm run build -- runtime-cjs,server-renderer", "build:types": "rimraf temp && tsc --declaration --emitDeclarationOnly --outDir temp && api-extractor run && api-extractor run -c packages/compiler-sfc/api-extractor.json", "test": "npm run ts-check && npm run test:types && npm run test:unit && npm run test:e2e && npm run test:ssr && npm run test:sfc", "test:unit": "vitest run test/unit", "test:ssr": "npm run build:ssr && vitest run server-renderer", "test:sfc": "vitest run compiler-sfc", "test:e2e": "npm run build -- full-prod,server-renderer-basic && vitest run test/e2e", "test:transition": "karma start test/transition/karma.conf.js", "test:types": "npm run build:types && tsc -p ./types/tsconfig.json", "format": "prettier --write --parser typescript \"(src|test|packages|types)/**/*.ts\"", "ts-check": "tsc -p tsconfig.json --noEmit", "ts-check:test": "tsc -p test/tsconfig.json --noEmit", "bench:ssr": "npm run build:ssr && node benchmarks/ssr/renderToString.js && node benchmarks/ssr/renderToStream.js", "release": "node scripts/release.js", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s" }, "gitHooks": { "pre-commit": "lint-staged", "commit-msg": "node scripts/verify-commit-msg.js" }, "lint-staged": { "*.js": ["prettier --write"], "*.ts": ["prettier --parser=typescript --write"] }, "repository": { "type": "git", "url": "git+https://github.com/vuejs/vue.git" }, "keywords": ["vue"], "author": "Evan You", "license": "MIT", "bugs": { "url": "https://github.com/vuejs/vue/issues" }, "homepage": "https://github.com/vuejs/vue#readme", "dependencies": { "@vue/compiler-sfc": "workspace:*", "csstype": "^3.1.0" }, "devDependencies": { "@babel/parser": "^7.23.5", "@microsoft/api-extractor": "^7.25.0", "@rollup/plugin-alias": "^3.1.9", "@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-node-resolve": "^13.3.0", "@rollup/plugin-replace": "^4.0.0", "@types/he": "^1.1.2", "@types/node": "^20.10.3", "chalk": "^4.1.2", "conventional-changelog-cli": "^2.2.2", "cross-spawn": "^7.0.3", "enquirer": "^2.3.6", "esbuild": "^0.19.8", "execa": "^4.1.0", "he": "^1.2.0", "jasmine-core": "^4.2.0", "jsdom": "^19.0.0", "karma": "^6.3.20", "karma-chrome-launcher": "^3.1.1", "karma-cli": "^2.0.0", "karma-esbuild": "^2.2.5", "karma-jasmine": "^5.0.1", "lint-staged": "^12.5.0", "lodash": "^4.17.21", "marked": "^4.0.16", "minimist": "^1.2.6", "postcss": "^8.4.14", "prettier": "^2.6.2", "puppeteer": "^14.3.0", "rimraf": "^3.0.2", "rollup": "^2.79.1", "rollup-plugin-typescript2": "^0.32.0", "semver": "^7.3.7", "shelljs": "^0.8.5", "terser": "^5.14.0", "todomvc-app-css": "^2.4.2", "ts-node": "^10.8.1", "tslib": "^2.4.0", "typescript": "^4.8.4", "vitest": "^1.0.4", "yorkie": "^2.0.0" } }