本文介绍了如何收缩包装 devDependencies,但除非必要,否则不安装它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一堆 devDependencies 来运行测试套件,并使用 npm shrinkwrap 锁定生产依赖项.问题是当我运行 npm install 时,只安装了生产依赖项,为了安装 devDependencies,我必须删除 npm-shrinkwrap.json 并再次运行它.

I have a bunch of devDependencies needed in order to run test suite and have production dependencies locked down with npm shrinkwrap. The problem is that when I run npm install, only production dependencies are installed, in order to install devDependencies, I have to remove npm-shrinkwrap.json and run it again.

现在,如果shrinkwrap 也包含devDependencies,它们就会安装在生产环境中,而在生产环境中不需要它们.当然应该有一些命令行参数来强制只安装正常的依赖项?

Now if shrinkwrap contains devDependencies as well, they get installed in production, where they are not required. Surely there should be some command line arguments to force only normal dependencies to be installed?

推荐答案

2016 年 9 月:

正如其他人所提到的,从 npm v3 开始,有一些巨大的努力来增强收缩包装功能.10.8.

As others have mentioned as well, there were some huge efforts to enhance the shrinkwrap feature starting with npm v3.10.8.

多亏了这个,才有可能保持您的devDependencies 被锁定仅安装生产依赖项时:

Thanks to this, it'll be possible to keep your devDependencies locked while installing only the production dependencies:

npm shrinkwrap --dev
npm install --only=prod

2013 年回答:

NPM 文档所述:

由于 npm shrinkwrap 旨在锁定您的依赖项生产使用,devDependencies 不会被包括在内,除非你运行 npm shrinkwrap 时显式设置 --dev 标志.如果已安装的 devDependencies 被排除,然后 npm 将打印警告.如果您希望它们默认与您的模块一起安装,请考虑将它们添加到依赖项中.

基本上,或者您锁定所有部门,或仅锁定生产部门.

Basically, or you lock down all deps, or only the production deps.

即使运行 npm install --devnpm install --force 也无法超越收缩包装功能.

Not even running npm install --dev or npm install --force can transcend the shrinkwrap functionality.

这篇关于如何收缩包装 devDependencies,但除非必要,否则不安装它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 18:54