有没有办法让 "npm ci" 安装 devDependencies,或者 "npm install" 不更新包 - lock.json?

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

我正在尝试为在本地开发环境中安装我们的代码库的新开发人员整理文档。我想给他们这样的命令:

"npm ci" 几乎完全符合我的要求,但似乎没有安装 devDependencies。 "npm install" 确实安装了 devDependencies,但它有时会修改 package-lock.json。

我可以想象像 "npm install && git checkout package-lock.json" 这样的简陋的东西,但我觉得必须有一种更地道的说法 "give me a clean install of this project's dependencies for development?"

npm ci 确实安装了依赖项和开发依赖项。但是,如果您使用 npm ci --production 或者如果您的 NODE_ENV 设置为生产环境,那么它会避免安装开发依赖项。 请检查文档 here.

With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.

NOTE: The --production flag has no particular meaning when adding a dependency to a project.

覆盖 NODE_ENV 变量

当您的 NODE_ENV 环境变量设置为 production 时,使用 npm ci 将不会安装 devDependencies。但是如果你还想安装 devDependencies

npm ci --include=dev

会成功的 ;)


对于早于 NPM v7.x 的版本,使用

npm ci --also=dev