简体   繁体   English

最好通过NPM或Bower安装下划线?

[英]Better to install underscore via NPM or Bower?

I'm building a NodeJS app and using UnderscoreJS. 我正在构建一个NodeJS应用程序并使用UnderscoreJS。 Would it be more applicable as a Bower or NPM installation? 是否更适用于Bower或NPM安装? Is there actually any difference? 实际上有什么区别吗? I'm using it on front and back-end. 我在前端和后端使用它。 What's the proper way? 什么是正确的方法?

It's already answered here : What is the difference between Bower and npm? 这里已经回答: Bower和npm有什么区别?

So, Here is the answer: 那么,这是答案:

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. npm最常用于管理Node.js模块,但当与Browserify和/或$ npm重复数据删除相结合时,它也适用于前端。

Bower is created solely for the front-end and is optimized with that in mind. Bower专为前端而设计,并以此为基础进行了优化。 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). 最大的区别是npm执行嵌套依赖树(大小很重),而Bower需要一个平面依赖树(将依赖解析的负担放在用户身上)。

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 eg their own version of Underscore. 它让您不必关心依赖冲突,因为所有依赖项都使用例如他们自己的Underscore版本。 This obviously doesn't work that well on the front-end. 这显然不会在前端工作得那么好。 Imagine a site having to download three copies of jQuery. 想象一个网站必须下载三个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. 许多项目使用两者的原因是他们使用Bower作为前端软件包,npm用于开发人员工具,如Yeoman,Grunt,Gulp,JSHint,CoffeeScript等。

All package managers have many downsides. 所有包管理器都有许多缺点。 You just have to pick which you can live with. 你只需挑选你可以忍受的东西。

Using Bower is better. 使用Bower更好。 This allows you to automatically keep your dependencies up to date, plus you can add them to index automatically with grunt. 这允许您自动使您的依赖项保持最新, 另外您可以使用grunt自动将它们添加到索引中。

bower install underscore; grunt bowerInstall;

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

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