简体   繁体   English

有没有办法让“npm ci”安装 devDependencies 或“npm install”不更新 package-lock.json?

[英]Is there a way of making "npm ci" install devDependencies, or "npm install" not update package-lock.json?

I'm trying to put together documentation for new developers installing our codebase on their local development environments.我正在尝试为新开发人员在他们的本地开发环境中安装我们的代码库整理文档。 I'd like to give them command(s) that:我想给他们命令:

  • Installs both devDependencies and dependencies based on the versions in package-lock.json根据 package-lock.json 中的版本安装 devDependencies 和依赖项
  • Doesn't update package-lock.json不更新 package-lock.json

"npm ci" does almost exactly what I want, but doesn't seem to install devDependencies. “npm ci”几乎完全符合我的要求,但似乎没有安装 devDependencies。 "npm install" does install devDependencies, but it sometimes modifies package-lock.json. “npm install”确实会安装 devDependencies,但它有时会修改 package-lock.json。

I could imagine something janky like "npm install && git checkout package-lock.json", but I feel like there must be a more idiomatic way of saying "give me a clean install of this project's dependencies for development?"我可以想象像“npm install && git checkout package-lock.json”之类的东西,但我觉得必须有一种更惯用的方式来表达“给我一个干净安装这个项目的开发依赖项?”

npm ci does install both dependecies and dev dependencies. npm ci确实安装了依赖项和开发依赖项。 But if you use npm ci --production or if your NODE_ENV is set to production, then it avoids installing dev dependencies.但是如果你使用npm ci --production或者如果你的NODE_ENV设置为生产,那么它避免安装开发依赖项。 Please check docs here .在此处查看文档。

With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.使用--production标志(或当NODE_ENV环境变量设置为生产时),npm 将不会安装 devDependencies 中列出的模块。

NOTE: The --production flag has no particular meaning when adding a dependency to a project.注意:在向项目添加依赖项时,-- --production标志没有特殊意义。

Override NODE_ENV variable覆盖NODE_ENV变量

When your NODE_ENV environment variable is set to production , using npm ci will not install devDependencies.当您的NODE_ENV环境变量设置为production 时,使用npm ci将不会安装 devDependencies。 But if you still want to install devDependencies但是如果你还想安装devDependencies

npm ci --include=dev

will do the trick ;)会做的伎俩;)


For versions older than NPM v7.x, use对于早于 NPM v7.x 的版本,请使用

npm ci --also=dev

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

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