{//名称
"name": "vue",//版本
"version": "2.6.10",//描述
"description": "Reactive, component-oriented view layer for modern web interfaces.",//npm包项目的主要入口文件,必须的
"main": "dist/vue.runtime.common.js",//rollup 打包需要的入口文件
"module": "dist/vue.runtime.esm.js",//npm 上所有的文件都开启 cdn 服务地址
"unpkg": "dist/vue.js",//jsdelivr cdn公共库
"jsdelivr": "dist/vue.js",//TypeScript 的入口文件
"typings": "types/index.d.ts",//当你发布package时,具体那些文件会发布上去
"files": ["src","dist/*.js","types/*.d.ts"],//声明该模块是否包含 sideEffects(副作用),从而可以为 tree-shaking 提供更大的优化空间。
"sideEffects": false,"scripts": {"dev": "rollup -w -c scripts/config.js --environment TARGET:web-full-dev","dev:cjs": "rollup -w -c scripts/config.js --environment TARGET:web-runtime-cjs-dev","dev:esm": "rollup -w -c scripts/config.js --environment TARGET:web-runtime-esm","dev:test": "karma start test/unit/karma.dev.config.js","dev:ssr": "rollup -w -c scripts/config.js --environment TARGET:web-server-renderer","dev:compiler": "rollup -w -c scripts/config.js --environment TARGET:web-compiler ","dev:weex": "rollup -w -c scripts/config.js --environment TARGET:weex-framework","dev:weex:factory": "rollup -w -c scripts/config.js --environment TARGET:weex-factory","dev:weex:compiler": "rollup -w -c scripts/config.js --environment TARGET:weex-compiler ","build": "node scripts/build.js","build:ssr": "npm run build -- web-runtime-cjs,web-server-renderer","build:weex": "npm run build -- weex","test": "npm run lint && flow check && npm run test:types && npm run test:cover && npm run test:e2e -- --env phantomjs && npm run test:ssr && npm run test:weex","test:unit": "karma start test/unit/karma.unit.config.js","test:cover": "karma start test/unit/karma.cover.config.js","test:e2e": "npm run build -- web-full-prod,web-server-basic-renderer && node test/e2e/runner.js","test:weex": "npm run build:weex && jasmine JASMINE_CONFIG_PATH=test/weex/jasmine.js","test:ssr": "npm run build:ssr && jasmine JASMINE_CONFIG_PATH=test/ssr/jasmine.js","test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2","test:types": "tsc -p ./types/test/tsconfig.json","lint": "eslint src scripts test","flow": "flow check","sauce": "karma start test/unit/karma.sauce.config.js","bench:ssr": "npm run build:ssr && node benchmarks/ssr/renderToString.js && node benchmarks/ssr/renderToStream.js","release": "bash scripts/release.sh","release:weex": "bash scripts/release-weex.sh","release:note": "node scripts/gen-release-note.js","commit": "git-cz"},//代码质量检查
"gitHooks": {"pre-commit": "lint-staged","commit-msg": "node scripts/verify-commit-msg.js"},//代码检查
"lint-staged": {"*.js": ["eslint --fix","git add"]
},//git仓库所在位置
"repository": {"type": "git","url": "git+https://github.com/vuejs/vue.git"},//关键词
"keywords": ["vue"],//作者
"author": "Evan You",//开源协议
"license": "MIT",//bug地址
"bugs": {"url": "https://github.com/vuejs/vue/issues"},//主页
"homepage": "https://github.com/vuejs/vue#readme",//依赖
"devDependencies": {"@babel/core": "^7.0.0","@babel/plugin-proposal-class-properties": "^7.1.0","@babel/plugin-syntax-dynamic-import": "^7.0.0","@babel/plugin-syntax-jsx": "^7.0.0","@babel/plugin-transform-flow-strip-types": "^7.0.0","@babel/preset-env": "^7.0.0","@babel/register": "^7.0.0","@types/node": "^10.12.18","@types/webpack": "^4.4.22","acorn": "^5.2.1","babel-eslint": "^10.0.1","babel-helper-vue-jsx-merge-props": "^2.0.3","babel-loader": "^8.0.4","babel-plugin-istanbul": "^5.1.0","babel-plugin-transform-vue-jsx": "^4.0.1","babel-preset-flow-vue": "^1.0.0","buble": "^0.19.3","chalk": "^2.3.0","chromedriver": "^2.45.0","codecov": "^3.0.0","commitizen": "^2.9.6","conventional-changelog": "^1.1.3","cross-spawn": "^6.0.5","cz-conventional-changelog": "^2.0.0","de-indent": "^1.0.2","es6-promise": "^4.1.0","escodegen": "^1.8.1","eslint": "^5.7.0","eslint-plugin-flowtype": "^2.34.0","eslint-plugin-jasmine": "^2.8.4","file-loader": "^3.0.1","flow-bin": "^0.61.0","hash-sum": "^1.0.2","he": "^1.1.1","http-server": "^0.11.1","jasmine": "^2.99.0","jasmine-core": "^2.99.0","karma": "^3.1.1","karma-chrome-launcher": "^2.1.1","karma-coverage": "^1.1.1","karma-firefox-launcher": "^1.0.1","karma-jasmine": "^1.1.0","karma-mocha-reporter": "^2.2.3","karma-phantomjs-launcher": "^1.0.4","karma-safari-launcher": "^1.0.0","karma-sauce-launcher": "^2.0.2","karma-sourcemap-loader": "^0.3.7","karma-webpack": "^4.0.0-rc.2","lint-staged": "^8.0.0","lodash": "^4.17.4","lodash.template": "^4.4.0","lodash.uniq": "^4.5.0","lru-cache": "^5.1.1","nightwatch": "^0.9.16","nightwatch-helpers": "^1.2.0","phantomjs-prebuilt": "^2.1.14","puppeteer": "^1.11.0","resolve": "^1.3.3","rollup": "^1.0.0","rollup-plugin-alias": "^1.3.1","rollup-plugin-buble": "^0.19.6","rollup-plugin-commonjs": "^9.2.0","rollup-plugin-flow-no-whitespace": "^1.0.0","rollup-plugin-node-resolve": "^4.0.0","rollup-plugin-replace": "^2.0.0","selenium-server": "^2.53.1","serialize-javascript": "^1.3.0","shelljs": "^0.8.1","terser": "^3.10.2","typescript": "^3.1.3","webpack": "~4.28.4","weex-js-runtime": "^0.23.6","weex-styler": "^0.3.0","yorkie": "^2.0.0"},//设置一些用于npm包的脚本命令会用到的配置参数
"config": {"commitizen": {"path": "./node_modules/cz-conventional-changelog"}
}
}
View Code
说明:作为包的 package.json 文件 和 作为顶层项目目录下的 package.json 是有点区别。项目目录下 的 package 文件 ,字段不是 很严格的要求。
1、main :npm包项目的主要入口文件,必须的。
2、typings: TypeScript 的入口文件。【npm 包中 package.json 可能会有,项目下的 根据开发者自己定】
个人理解:typings 字段 就是方便 IDE 识别、编译、智能提示 js 语法的 工具。项目中 引入包,根据 main字段 引入文件的。
typings 的入口文件 里面的代码 只是 为 编辑器 智能提示 服务的【同时,开发人员 通过这个 文件,可以找到 某个方法具体有哪些 参数 以及 参数类型】。
真正执行的程序是不会执行 这里面的 代码的;所以 编辑器 跳转 是先根据 typings 字段进行跳转的,如果 没有这个字段 再跳转 main 字段的文件。
经验:webstorm中npm包的 类型声明 中 interface 定义的类型 类型变量,跳转时 可以跳转 到 ts 的源 文件的定义处。
npm 包 设定的版本规则:主版本号.次版本号.修补版本号
version :指定版本。比如1.2.2,遵循“大版本.次要版本.小版本”的格式规定,安装时只安装指定版本。
~version:大概匹配某个版本。比如~1.2.2,表示安装1.2.x的最新版本(不低于1.2.2),但是不安装1.3.x,也就是说安装时不改变大版本号和次要版本号。
^version:兼容某个版本。比如ˆ1.2.2,表示安装1.x.x的最新版本(不低于1.2.2),但是不安装2.x.x,也就是说安装时不改变大版本号。
latest :安装最新版本。
>version:必须大于某个版本。
>=version:可大于或等于某个版本。
X :x号的位置表示任意版本。如:1.2.x,表示可以1.2.0,1.2.1,…,1.2.n
扩展:
a、npm 包 要使 编辑器有 智能提示,有 两种方法:使用 TypeScript 编写 源代码,或者 给 JS 添加 TS 的类型声明文件 index.d.ts 。
JS 的 类型 声明 文件 都是 以 .d.ts 作为后缀名 的文件,在里面写各种提示的逻辑【只是提示的逻辑,而不是程序 执行的 逻辑】。
2、