NPM 从 package.json 安装依赖项

Kay*_*ote 2 javascript dependencies node.js npm package.json

我有点困惑。在我的笔记本电脑上,当我建立我的项目时,我package.json在安装它们时填充了依赖项。

它看起来像这样:

"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"
  },
Run Code Online (Sandbox Code Playgroud)

现在,在我的新系统上,拉了 repo & 的印象是我必须调用的是npm install& npm 将读取 package.json & 下载所有依赖项及其指定的版本。那没有发生。

所以,我的问题是,我们如何正确地将所有这些依赖项安装到新系统上。

会不会是跑步的问题 npm i --save [all the dependencies]

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

另外,如果我执行上述操作,将如何解决版本号?我的意思是, package.json 具有指定的版本,同时运行上述两个命令将下载每个包的最新版本。

非常感谢,

ale*_*mac 5

如果要安装符合版本要求的最新模块版本,应使用以下命令:

npm i
Run Code Online (Sandbox Code Playgroud)

在这种情况下,immutable例如,对于模块,将安装最新的 3.x 版本。

但是,如果您想安装您的第一台开发电脑相同的版本,您还需要执行以下操作:

npm shrinkwrap # run this command on first pc 
npm i          # run this command on a new pc
Run Code Online (Sandbox Code Playgroud)