通常我们使用npm init命令来创建一个npm程序时,会自动生成一个package.json文件。package.json文件会描述这个NPM包的所有相关信息,包括作者、简介、包依赖、构建等信息,
1.先看一下一个完整package.json文件
{
"name": "by_iview2.0",
"version": "1.0.0",
"description": "sims by iview2.0",
"author": "xie",
"private": true,
"scripts": {
"dev": "node build/dev-server.js",
"build": "node build/build.js"
},
"dependencies": {
"mui": "^1.0.0",
"iview": "^2.0.0-rc.4",
"vue": "^2.2.2",
"vue-router": "^2.2.0",
"vue-resource":"^1.3.1"
},
"devDependencies": {
"autoprefixer": "^6.7.2",
"babel-core": "^6.22.1",
"babel-loader": "^6.2.10",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.2.1",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chalk": "^1.1.3",
"mock-api":"^0.1.5",
"connect-history-api-fallback": "^1.3.0",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.26.1",
"eventsource-polyfill": "^0.9.6",
"express": "^4.14.1",
"extract-text-webpack-plugin": "^2.0.0",
"file-loader": "^0.10.0",
"friendly-errors-webpack-plugin": "^1.1.3",
"function-bind": "^1.1.0",
"html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"opn": "^4.0.2",
"optimize-css-assets-webpack-plugin": "^1.3.0",
"ora": "^1.1.0",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"url-loader": "^0.5.7",
"vue-html5-editor": "^1.0.1",
"vue-loader": "^11.1.4",
"vue-style-loader": "^2.0.0",
"vue-template-compiler": "^2.2.1",
"webpack": "^2.2.1",
"webpack-bundle-analyzer": "^2.2.1",
"webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.16.1",
"webpack-merge": "^2.6.1"
}
2.主要属性的介绍
1.script
通过设置这个可以使NPM调用一些命令脚本,封装一些功能。
"scripts": {
"dev": "node build/dev-server.js",
"build": "node build/build.js"
}
”dev”和”build”。运行”npm run dev”的时候执行的是build/dev-server.js文件,运行”npm run build”的时候执行的是build/build.js文件,后续会对这两个文件开始进行代码阅读分析。
2.dependencies
指定依赖的其它包,这些依赖是指包发布后正常执行时所需要的,也就是线上需要的包。如果是开发中依赖的包,可以在devDependencies设置。
"dependencies": {
"mui": "^1.0.0",
"iview": "^2.0.0-rc.4",
"vue": "^2.2.2",
"vue-router": "^2.2.0",
"vue-resource":"^1.3.1"
}
3.devDependencies
这些依赖只有在开发时候才需要,上线部署不需要打包进去。
"autoprefixer": "^6.7.2",
"babel-core": "^6.22.1",
"babel-loader": "^6.2.10",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.2.1",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chalk": "^1.1.3",
"mock-api":"^0.1.5",
"connect-history-api-fallback": "^1.3.0",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.26.1",
"eventsource-polyfill": "^0.9.6",
"express": "^4.14.1",
"extract-text-webpack-plugin": "^2.0.0",
"file-loader": "^0.10.0",
"friendly-errors-webpack-plugin": "^1.1.3",
"function-bind": "^1.1.0",
"html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"opn": "^4.0.2",
"optimize-css-assets-webpack-plugin": "^1.3.0",
"ora": "^1.1.0",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"url-loader": "^0.5.7",
"vue-html5-editor": "^1.0.1",
"vue-loader": "^11.1.4",
"vue-style-loader": "^2.0.0",
"vue-template-compiler": "^2.2.1",
"webpack": "^2.2.1",
"webpack-bundle-analyzer": "^2.2.1",
"webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.16.1",
"webpack-merge": "^2.6.1"
}