简体   繁体   English

npm/yarn 默认安装 devDependencies 吗?

[英]Does npm/yarn install devDependencies by default?

I'm working on private library of react components.我正在研究反应组件的私有库。 I've already setup the whole workflow etc. but I'm not sure about one thing.我已经设置了整个工作流程等,但我不确定一件事。

In my library I have some packages listed as peerDependencies which have to be peer ones (for example react , cuz only one instance of react can be installed at once, otherwise everything breaks).在我的库中,我有一些列为peerDependencies的包,它们必须是对等的(例如react ,因为一次只能安装一个 react 实例,否则一切都会中断)。 But if I'd like to setup some tests in my library I need react installed there as devDependency .但是,如果我想在我的库中设置一些测试,我需要将react安装为devDependency

So I have to install react as peer and dev in library.所以我必须在库中安装 react 作为peerdev And what happens when I publish this package to npm register?当我将此 package 发布到 npm 寄存器时会发生什么? devDependencies are excluded here? devDependencies被排除在外了吗?

Thanks!谢谢!

If you create a node package, and you have some dev dependencies, npm wont count them for the publish.如果您创建一个节点 package,并且您有一些开发依赖项,则 npm 不会将它们计入发布。 That's why it's called devDependencies .这就是为什么它被称为devDependencies It's not under the production code.它不在生产代码下。

I know you have to specify when installing an npm package --save-dev so it saves dependencies onto your json file.我知道您必须在安装 npm package --save-dev 时指定,以便将依赖项保存到您的 json 文件中。

If you need it in production, add it to peerDependencies .如果您在生产中需要它,请将其添加到peerDependencies Otherwise, leave it in devDependencies .否则,将其留在devDependencies中。 When someone installs your library, dev dependencies won't be installed, and peer dependencies should already be installed.当有人安装您的库时,不会安装开发依赖项,并且应该已经安装了对等依赖项。

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

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