为什么使用 gems 来提供资产而不是供应商文件? [英] Why use gems for serving assets instead of the vendor file?

查看:35
本文介绍了为什么使用 gems 来提供资产而不是供应商文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Rails 比较陌生,我有一个关于从 gem 提供资产与仅将文件加载到资产管道中的问题.

I am relatively new to Rails and I have a question about serving assets from a gem vs just loading the files into the asset pipeline.

据我所知,它们实际上做了相同的事情,因为它们都使资产管道中的文件可用,以便在清单中调用.

As far as I can tell, they do virtually the same thing in that they both make the files available in the asset pipeline to be called in the manifest.

gem 'jquery-rails'

之类的东西作为 gem 而不是仅仅将

as a gem instead of just putting

/vendor/assets/javascripts/jQuery.js

放在供应商资产并以这种方式加载?

in the vendor assets and loading it that way?

推荐答案

优点是您不必将文件添加到存储库并管理更新,您更新 gem 并更新依赖项.他们还可以添加助手以更轻松地使用资产.

The advantage is you don't have to add the file(s) to your repo and manage updates, you update the gem and you've updated the dependency. They can also add helpers to use the assets more easily.

并非所有 JS/CSS 项目都与资产管道开箱即用,因此有时 gems 也可以为您工作.

Not all JS/CSS projects are out-of-the-box compatible with the asset pipeline too, so sometimes the gems will do that work for you as well.

仅仅因为文件被提供给客户端并不会使它与您的应用程序中的任何其他依赖项有太大不同.

Just because the files get served to clients doesn't make it much different than any other dependency in your application.

这篇关于为什么使用 gems 来提供资产而不是供应商文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆