gpt4 book ai didi

node.js - 最好通过 NPM 或 Bower 安装下划线?

转载 作者:搜寻专家 更新时间:2023-10-31 22:58:34 28 4
gpt4 key购买 nike

我正在构建一个 NodeJS 应用程序并使用 UnderscoreJS。它作为 Bower 或 NPM 安装会更适用吗?实际上有什么区别吗?我在前端和后端使用它。什么是正确的方法?

最佳答案

这里已经回答了:What is the difference between Bower and npm?

所以,这是答案:

npm is most commonly used for managing Node.js modules, but it works for the front-end too when combined with Browserify and/or $ npm dedupe.

Bower is created solely for the front-end and is optimized with that in mind. The biggest difference is that npm does nested dependency tree (size heavy) while Bower requires a flat dependency tree (puts the burden of dependency resolution on the user).

A nested dependency tree means that your dependencies can have its own dependencies which can have their own, and so on. This is really great on the server where you don't have to care much about space and latency. It lets you not have to care about dependency conflicts as all your dependencies use e.g. their own version of Underscore. This obviously doesn't work that well on the front-end. Imagine a site having to download three copies of jQuery.

The reason many projects use both is that they use Bower for front-end packages and npm for developer tools like Yeoman, Grunt, Gulp, JSHint, CoffeeScript, etc.

All package managers have many downsides. You just have to pick which you can live with.

关于node.js - 最好通过 NPM 或 Bower 安装下划线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24709865/

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