gpt4 book ai didi

npm:依赖项与具有捆绑依赖项的 devDependencies

转载 作者:行者123 更新时间:2023-12-01 13:45:56 25 4
gpt4 key购买 nike

使用搜索,我已经找到了类似问题的一些很好的答案,但我仍然不确定我是否理解正确。

从这些答案中我了解到 dependencies需要在 devDependencies 时运行应用程序仅在开发时需要(如单元测试)。

但是这个怎么样:我的应用程序依赖于 jQuery,但是在构建步骤期间(在我的 devDependencies 的帮助下),所有内容都捆绑到一个文件中。在这种情况下,我应该将 jQuery 列为 dependency或作为 devDependency ?

为了让我的观点更清楚,请使用这样的模块:

define(['jquery'], function($) {
// use jQuery in this module
})

稍后,这个模块将被编译成类似 application.build.js 的东西。然后包含此模块和 jQuery 依赖项。

最佳答案

由于最终结果是一样的,这里似乎没有一个明确的规则,但我发现了一些关于这个问题的讨论:
如果您正在构建应用程序
https://github.com/webpack/webpack/issues/520

A browser app built by [insert build tool/bundler] has no runtime node dependencies, and thus all frontend dependencies should be listed as devDependencies. The dependencies vs devDependencies naming convention stems historically from node being a server side package manager (...) It is as far as I can tell harmless to list frontend dependencies under dependencies, but it is wrong.



(...) as a general recommendation for everyone, move everything into devDependencies until it is actually needed under dependencies.


如果你正在构建一个库:
https://github.com/inuitcss/inuitcss/issues/225

In many frontend projects, all code served to the browser is compiled, there are no runtime dependencies. This would mean that there are no dependencies, only devDependencies – all dependencies are included in the build done during development.

One could also argue that dependencies are required for development as well, so it would be okay to list everything unter dependencies.



I think the fact that we have the optional distinction indicates a reasonable way to use them. It makes sense (to me) that the dependencies designation would represent the 'minimum viable' code to use and as an indicator of what's nonessential for something to work.



As I see it, anything that goes on to become part of the production code is a dependency.


结语
就个人而言,我更同意最后一句话。 dependencies 是有道理的告诉我们应用程序代码需要运行什么, devDependencies开发人员需要构建/部署/任何应用程序/库。
不过需要注意的是,如果有人 npm install s 你的库在他们自己的应用程序中使用捆绑包作为一个模块,他们会下载很多 dependencies他们实际上并不需要。

关于npm:依赖项与具有捆绑依赖项的 devDependencies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36218100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com