nodejs模块依赖及版本号

摘要

Node.js最重要的一个文件就是package.json,其中的配置参数决定了功能。例如下面就是一个例子

nodejs模块依赖及版本号

这个是我下载的demo的package.json文件

{
  "private": true,
  "entry": {
    "index": "./src/index.js"
  },
  "dependencies": {
    "antd": "^2.7.3",
    "classnames": "^2.2.5",
    "dva": "^1.1.0",
    "dva-loading": "^0.2.0",
    "js-cookie": "^2.1.3",
    "lodash": "^4.17.4",
    "qs": "^6.2.0",
    "react": "^15.4.1",
    "react-countup": "1.3.0",
    "react-dom": "^15.4.1",
    "recharts": "^0.19.0"
  },
  "devDependencies": {
    "atool-build": "^0.7.6",
    "babel-eslint": "^6.0.4",
    "babel-plugin-dev-expression": "^0.2.1",
    "babel-plugin-dva-hmr": "^0.1.0",
    "babel-plugin-import": "^1.0.1",
    "babel-plugin-transform-runtime": "^6.9.0",
    "babel-polyfill": "^6.23.0",
    "babel-runtime": "^6.9.2",
    "dora": "^0.4.3",
    "dora-plugin-browser-history": "^0.2.0",
    "dora-plugin-proxy": "^0.8.5",
    "dora-plugin-<a href="http://www.ldhblog.com/tag/web/" title="查看与 web 相关的文章"target="_blank">web</a>pack": "^0.8.1",
    "dora-plugin-<a href="http://www.ldhblog.com/tag/web/" title="查看与 web 相关的文章"target="_blank">web</a>pack-hmr": "^0.2.1",
    "eslint": "^3.17.1",
    "eslint-config-airbnb": "^9.0.1",
    "eslint-plugin-import": "^1.16.0",
    "eslint-plugin-jsx-a11y": "^1.4.2",
    "eslint-plugin-react": "^5.1.1",
    "glob": "^7.0.5",
    "mockjs": "^1.0.1-beta3",
    "rc-tween-one": "^1.0.0",
    "redbox-react": "^1.2.10",
    "robe-<a href="http://www.ldhblog.com/tag/ajax/" title="查看与 ajax 相关的文章"target="_blank">ajax</a>": "^1.0.0",
    "watchjs": "^0.0.0"
  },
  "scr<a href="http://www.ldhblog.com/tag/ip/" title="查看与 ip 相关的文章"target="_blank">ip</a>ts": {
    "start": "dora --plugins \"proxy,webpack?publicPath=/,webpack-hmr,browser-history?index=/src/index.<a href="http://www.ldhblog.com/tag/html/" title="查看与 html 相关的文章"target="_blank">html</a>\"",
    "dev": "dora --plugins \"webpack?publicPath=/,webpack-hmr,browser-history?index=/src/index.html\"",
    "lint": "eslint --fix --ext .js src",
    "build": "atool-build"
  },
  "theme": "./src/theme.js",
  "standard": {
    "parser": "babel-eslint",
    "globals": [
      "location",
      "localStorage"
    ]
  }
}

dependencies与devDependencies:

一个node package有两种依赖,一种是dependencies,另一种是devDependencies,其中前者依赖的项是正常运行该包时所需要的依赖项,而后者则是开发的时候需要的依赖项,像一些进行单元测试之类的包。简单来记就是下面的

“dependencies”: {}     //生产环境

“devDependencies”: {}//开发环境

在package.json所在目录执行npm install的时候,devDependencies里面的模块也会被安装的。如果我们只想安装dependencies里面的包,可以执行

npm install –production

如果只安装devDependencies,可以执行

npm install –dev

同理,使用npm install node_module –save自动更新dependencies字段值,使用npm install node_module –save-dev自动更新devDependencies字段值。

版本号:

每一个模块后面对应的就是他的版本号,如”^4.10.1″。下面是几个版本的表达式

表达式 版本范围
>=1.2.7 大于等于1.2.7
>=1.2.7 <1.3.0 1.2.7,1.2.8,1.2.9
1.2.3 – 2.3.4 >=1.2.3 <=2.3.4
1.2 – 2.3.4 >=1.2.0 <=2.3.4
1.2.3 – 2.3 >=1.2.3 <2.4.0
1.2.3 – 2 >=1.2.3 <3.0.0
* >=0.0.0
1.x(等价于1.X) >=1.0.0 <2.0.0
1.2.x >=1.2.0 <1.3.0
“”(等价于*) >=0.0.0
1(等价于1.x.x) >=1.0.0 <2.0.0
1.2(等价于1.2.x) >=1.2.0 <1.3.0
~1.2.3(>=1.2.3 <1.(2+1).0) >=1.2.3 <1.3.0
~1.2(>=1.2.0 <1.(2+1).0) >=1.2.0 <1.3.0
~1(>=1.0.0 <(1+1).0.0) >=1.0.0 <2.0.0
~0.2.3(>=0.2.3 <0.(2+1).0) >=0.2.3 <0.3.0
~0.2(>=0.2.0 <0.(2+1).0) >=0.2.0 <0.3.0
~0(>=0.0.0 <(0+1).0.0) >=0.0.0 <1.0.0
~1.2.3-beta.2 >=1.2.3-beta.2 <1.3.0
^1.2.3 >=1.2.3 <2.0.0
^0.2.3 >=0.2.3 <0.3.0
^0.0.3 >=0.0.3 <0.0.4
^1.2.3-beta.2 >=1.2.3-beta.2 <2.0.0
^0.0.3-beta >=0.0.3-beta <0.0.4
^1.2.x >=1.2.0 <2.0.0
^0.0.x >=0.0.0 <0.1.0
^0.0 >=0.0.0 <0.1.0
^1.x >=1.0.0 <2.0.0
^0.x >=0.0.0 <1.0.0

 

李东辉

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:3   其中:访客  2   博主  1

  1. avatar www.0371zzfk.com 0

    代码收藏了,以后估计用的上

  2. avatar 天壮物业 0

    现在网站不好做了啊