node.js JavaScript 依赖管理:npm vs. bower vs. volo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15092345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 13:42:03  来源:igfitidea点击:

JavaScript dependency management: npm vs. bower vs. volo

javascriptnode.jsnpmbowervolojs

提问by Yugal Jindle

How do you compare npm, bowerand volo?

你怎么比较npmbowervolo

All three can be used to install JavaScript dependencies for a UI project. I understand npmis more node specific.

所有这三个都可用于为 UI 项目安装 JavaScript 依赖项。我的理解npm是更具体的节点。

So, when to use what?

那么,什么时候使用呢?

npmstill stands distant, but bowerand voloseem to be solving exactly the same problem, although I am not able to draw a line between npmand bower-volo.

npm依然屹立遥远,但bowervolo似乎正好解决同样的问题,虽然我不是能画之间的线路npmbower-volo

采纳答案by strangeloops

A description that best describes the difference between npm and bower is: npm manages JavaScript modules called packages and Bower manages front-end components (i.e. css, html, and JavaScript) called components. npm is also used to install bower. Here is an expansive article on npm and bower(does not cover volo) it goes into plenty of detail.

最能描述 npm 和 bower 区别的描述是:npm 管理称为包的 JavaScript 模块,而 Bower 管理称为组件的前端组件(即 css、html 和 JavaScript)。npm 也用于安装 bower。这是一篇关于 npm 和 bower(不包括 volo)的详尽文章,其中详细介绍了很多细节。

回答by gustavohenke

bower

凉亭

It's still very popular among front-end developers, even though it has very few features. Every front-end package is using it. There is also an initiative to merge bower into npm.

它在前端开发人员中仍然很受欢迎,尽管它的功能很少。每个前端包都在使用它。还有一项将 bower 合并到 npm倡议

Bower is optimized for the client-side and supports only flat dependency trees, i.e. each library must be used only once(since it's expensive to ship different versions of the same library to the client), and the dependency constraints must be resolved by the user.

Bower 针对客户端进行了优化,仅支持平面依赖树,即每个库只能使用一次(因为将同一库的不同版本发送到客户端的成本很高),并且依赖约束必须由用户解决.

You can expect to find anything that is front-end related in the bower registry (bower search <some keyword>) -- in my opinion, that's the biggest advantage of bower in relation to other package managers.

您可以期望在 bower 注册表 ( bower search <some keyword>) 中找到任何与前端相关的东西——在我看来,这是 bower 相对于其他包管理器的最大优势。

volo

沃洛

I have still not used it for more than 5 minutes in years. Don't know about it, but from what I can seeit does include some build tool, which is very familiar to Grunt users.

多年来我仍然没有使用它超过 5 分钟。不知道它,但据我所知,它确实包含一些 Grunt 用户非常熟悉的构建工具。

npm

新产品经理

Yes, npm stands for Node Package Manager. But nowadays you can use it for everything; people are no longer only npm installing things and expecting them to work onlyin the Node environment. For example, there are many npm packages for Twitter Bootstrap.

是的,npm 代表节点包管理器。但是现在你可以用它来做任何事情;人们不再只是npm install处理事物并期望它们只能在 Node 环境中工作。例如,有很多用于 Twitter Bootstrap 的 npm 包

Npm is optimized for server-side usage, with a nested dependency tree. Each dependency can have its own dependencies which can have their own, and so on. This eliminated dependency version conflicts as each dependency can use their own version of e.g. Underscore. However, the upcoming npm version 3 will flatten the dependency tree:

Npm 针对服务器端使用进行了优化,具有嵌套的依赖树。每个依赖项都可以有自己的依赖项,这些依赖项可以有自己的依赖项,依此类推。这消除了依赖版本冲突,因为每个依赖都可以使用它们自己的版本,例如 Underscore。然而,即将推出的npm 版本 3 将扁平化依赖树

With npm@3, your node_modules directory will be a lot flatter. All of your dependencies and most of your subdependencies (and (sub)+dependencies) will be sitting next to each other at the top level. Only when there are conflicts will modules be installed at deeper levels. This should make things a lot easier for Windows users.

使用 npm@3,您的 node_modules 目录将更加平坦。您的所有依赖项和大多数子依赖项(和(子)+依赖项)将在顶层彼此相邻。只有当存在冲突时,才会在更深的层次上安装模块。对于 Windows 用户来说,这应该会让事情变得更容易。

Some advantages I see on using npm:

我看到使用 npm 的一些优势:

  • It's used by all the other package managers (component, bower, volo, JSPM, etc);
  • Allows using build scripts;
  • Lots of tools are available for introspecting npm-based packages
  • 所有其他包管理器(组件、凉亭、volo、JSPM 等)都使用它;
  • 允许使用构建脚本;
  • 许多工具可用于内省基于 npm 的包

npm is the package manager for JavaScript.

npm 是 JavaScript 的包管理器。

npmjs.com screenshot

npmjs.com 截图



As of february of 2013, my opinion was the following. Please don't take it into account anymore.

截至 2013 年 2 月,我的意见如下。请不要再考虑了。

npm

新产品经理

It's better to stick with it when you are with a Node project, there are very few projects that are available to browsers also...

当您使用 Node 项目时,最好坚持使用它,浏览器也可以使用的项目很少......

bower

凉亭

Bower is the pop guy right now. They have lots of projects under their hood, and the project maintainers like to keep them up-to-date in the bower registry...

Bower 现在是流行音乐人。他们有很多项目在他们的引擎盖下,项目维护者喜欢在 bower 注册表中保持它们的最新状态......

It's a shame that he's sometimes a little buggy.

很遗憾他有时会有点马车。

volo

沃洛

I haven't tried volo for more than 5 minutes since so, but from what I could see it looks to be more flexible than bower.

从那以后,我没有尝试过超过 5 分钟的 Volo,但从我所见,它看起来比 bower 更灵活。

A negative point for volo is that their projects are very outdated.

volo 的一个缺点是他们的项目非常过时。

回答by roy riojas

They seem to be solving the same problem but for different environments/worlds. NPM for nodejs and volo, bower for the browser.

他们似乎在解决相同的问题,但针对不同的环境/世界。用于 nodejs 和 volo 的 NPM,用于浏览器的 bower。

The truth is that you can use NPM also to manage javascript and css for the browser. There is nothing preventing you from doing it. In that sense using NPM feels more natural to me than having to manage two different tools for the same purpose.

事实是,您还可以使用 NPM 来管理浏览器的 javascript 和 css。没有什么可以阻止你这样做。从这个意义上说,使用 NPM 对我来说比为了同一目的而管理两个不同的工具更自然。

It seems that bower have more packages available, at least for the more popular ones. But soon jQuery will be also be available in NPM directlyand probably all the other libraries will follow the same trend.

似乎 bower 有更多可用的包,至少对于更受欢迎的包。但很快jQuery 也将直接在 NPM 中可用,可能所有其他库都将遵循相同的趋势。

In my opinion, since there are tools like browserifyand webmakeout there, that help use node modules in the browser, there is not anymore a real need for boweror volo, unless they offer something else for you (a particular module existing only in their registries).

在我看来,因为有一样的工具browserifywebmake在那里,在浏览器的帮助使用节点模块,没有了一个真正的需要凉亭VOLO,除非他们提供的东西别人为你(一个特定的模块只存在于他们的注册表)。

Both Voloand Bowerare good too, but from my point of view, if you're already using NPM, it might be better to stick to it.

无论瓦罗鲍尔也很好,但是从我的角度来看,如果你已经在使用NPM,它可能会更好地坚持下去。

Please note that you can use NPM to manage your client dependencies even without using browserify or webmake. In most of the projects I have being working on, after the npm modules are installed I run an script to deploy them to the location where my client app uses them. Sometimes I use grunt to concatenate that file with other js files and sometimes I reference it directly from the template files of my web apps. In any case, this is a personal preference. Others could find Bower or Volo easier to use as they fit more natural in their workflows.

请注意,即使不使用 browserify 或 webmake您也可以使用 NPM 来管理您的客户端依赖项。在我正在进行的大多数项目中,安装 npm 模块后,我运行一个脚本将它们部署到我的客户端应用程序使用它们的位置。有时我使用 grunt 将该文件与其他 js 文件连接起来,有时我直接从我的 Web 应用程序的模板文件中引用它。无论如何,这是个人喜好。其他人可能会发现 Bower 或 Volo 更易于使用,因为它们更适合他们的工作流程。

回答by wheresrhys

Bower's big advantage over NPM is that its dependency management enforces using a single version of a component (whereas NPM works by having different copies/versions as subdependencies of different modules). This is A VERY GOOD THINGbecause it prevents your client side javascript becoming bloated through needing to include multiple copies of a component at different versions. Including multiple copies of a module is central to how NPM's dependency management works, and NPM is therefore wholly unsuited to client side package management.

Bower 与 NPM 相比的一大优势在于,它的依赖管理强制使用组件的单个版本(而 NPM 通过将不同的副本/版本作为不同模块的子依赖来工作)。这是一件非常好的事情,因为它可以防止您的客户端 javascript 由于需要包含不同版本的组件的多个副本而变得臃肿。包含一个模块的多个副本是 NPM 的依赖管理如何工作的核心,因此 NPM 完全不适合客户端包管理。

A consequence of the above is that bower package maintainers and consumers have to be more mindful of maintaining their dependency version numbers to avoid conflicts, but it's a price worth paying. And I find NPM modules are often sloppy in their issuing of major, minor and patch releases so NPM dependency management isn't exactly a bed of roses either.

上述结果是 bower 包维护者和消费者必须更加注意维护他们的依赖版本号以避免冲突,但这是值得付出的代价。而且我发现 NPM 模块在发布主要版本、次要版本和补丁版本时通常很草率,因此 NPM 依赖项管理也不是一帆风顺。

回答by Bruce Lim

I know this isn't in the scope of the question but there's another alternative also. Jam JS - http://jamjs.org/One thing interesting is that it has grunt capabilities in jam:

我知道这不在问题的范围内,但还有另一种选择。Jam JS - http://jamjs.org/有趣的一件事是它在 jam 中具有 grunt 功能:

jam compile output.js

Someone should make yet another package manager and name it: yapm :)

有人应该制作另一个包管理器并将其命名为:yapm :)