简体   繁体   English

NPM从package.json安装依赖项

[英]NPM installing Dependencies from package.json

Im a bit confused. 我有点困惑。 On my laptop, as I built up my project, my package.json got populated with dependencies as I installed them. 在我的笔记本电脑上,当我建立项目时,我的package.json在安装它们时就充满了依赖性。

It looks like this: 看起来像这样:

"main": "webpack.config.js",
  "dependencies": {
    "immutable": "^3.7.6",
    "react": "^0.14.8",
    "react-dom": "^0.14.8",
    "react-redux": "^4.4.2",
    "redux": "^3.4.0"
  },
  "devDependencies": {
    "babel-core": "^6.7.6",
    "babel-loader": "^6.2.4",
    "babel-polyfill": "^6.7.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-react-hmre": "^1.1.1",
    "css-loader": "^0.23.1",
    "eslint": "^2.7.0",
    "eslint-loader": "^1.3.0",
    "eslint-plugin-react": "^4.3.0",
    "postcss-loader": "^0.8.2",
    "style-loader": "^0.13.0",
    "stylelint": "^4.5.1",
    "webpack": "^1.12.15",
    "webpack-dev-server": "^1.14.1",
    "webpack-merge": "^0.7.3"
  },

Now, on my new system, pulled the repo & was under the impression that all I have to call is npm install & npm would read package.json & download all the dependencies and their specified versions. 现在,在我的新系统上,拉出仓库,给人的印象是,我只需要打电话给npm install ,然后npm就会读取package.json并下载所有依赖项及其指定的版本。 That didnt happen. 那没有发生。

So, my question is, how do we correctly, install all of these dependencies onto a new system. 因此,我的问题是,我们如何正确地将所有这些依赖项安装到新系统上。

Would it be a matter of running npm i --save [all the dependencies] 是运行npm i --save [all the dependencies]的问题吗?

& npm i --save-dev [all the dev dependencies] npm i --save-dev [all the dev dependencies]

Also, how would the version number be resolved if I do the above? 另外,如果执行上述操作,将如何解析版本号? I mean, package.json has the versions specified while running the above two commands would download the latest versions of each package. 我的意思是,package.json具有在运行上述两个命令时指定的版本,将下载每个软件包的最新版本。

Many thanks, 非常感谢,

If you want to install the latest module versions meet the version requirements, you should use the command: 如果要安装符合版本要求的最新模块版本,则应使用以下命令:

npm i

In that case, for immutable module, for example, will be installed the latest 3.x version. 在这种情况下,例如,对于immutable模块,将安装最新的3.x版本。

But if you want to install the same versions as on your first development pc, you need too do the following: 但是,如果要安装第一台开发PC 相同的版本,则还需要执行以下操作:

npm shrinkwrap # run this command on first pc 
npm i          # run this command on a new pc

All you have to call is npm install, it will download the most recent major versions (^ caret range syntax) listed in dependencies and devDependencies 您需要调用的只是npm install,它将下载依赖项和devDependencies中列出的最新主要版本(^插入符范围语法)

https://docs.npmjs.com/cli/install https://docs.npmjs.com/cli/install

To install a specific version, remove the caret eg 要安装特定版本,请删除插入符号,例如

"react": "0.14.8",

You can use 'npm shrinkwrap' to lock down the versions of a package's dependencies -- creates a file npm-shrinkwrap.json containing the exact package versions in the entire hierarchy 您可以使用'npmrinkwrap'锁定软件包依赖项的版本-创建一个文件npm-shrinkwrap.json,其中包含整个层次结构中的确切软件包版本

https://docs.npmjs.com/cli/shrinkwrap https://docs.npmjs.com/cli/shrinkwrap


package.json interactive guide http://browsenpm.org/package.json package.json交互式指南http://browsenpm.org/package.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM