链轮中的链轮意味着什么
所以,我才刚刚意识到我完全不知道什么链轮在轨道上。
当使用bootstrap或实现时,请求在application.js
文件中包含sprocket
(bootstrap-sprocket或materialize-sprocket)。
我搜索的所有内容都谈到了资产管道,让我更加困惑。
根据ruby指南,
资产管道在技术上不再是Rails 4的核心function,它已从框架中提取到sprockets-rails gem中。
当我做bundle show sprockets-rails
,我得到了:
/Users/Sunday/workspace/resilience/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.1
这表明我至少拥有gem。
但我的困惑和我的问题是sprockets
的重要性是什么,而不是sprockets-rails
,它使其他gem像bootstrap
和materialize
,可能还有一些其他gem有sprockets
,特别是在他们的javascript文件中?
谢谢。
Sprockets是一个用于编译和提供Web资产的Ruby库。 Sprockets允许将应用程序的JavaScript文件组织成更小,更易于管理的块,这些块可以分布在多个目录和文件中。 它提供了有关如何在我们的项目中包含资产的结构和实践。
在每个JavaScript文件的开头使用指令,Sprockets可以确定JavaScript文件所依赖的文件。 在部署应用程序时,Sprockets然后使用这些指令将您的多个JavaScript文件转换为单个文件以获得更好的性能。
/app/assets/javascripts/application.js // This is a manifest file that'll be compiled into including all the files listed below. // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically // be included in the compiled file accessible from http://example.com/assets/application.js // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // //= require jquery //= require jquery_ujs //= require_tree .
application.js
文件称为清单,它由Sprockets
内部管理。 当请求进入此文件时, Sprockets
查看清单并将其中提到的每个文件编译在一起,并在此文件中的任何代码之前包含其内容。 Sprockets
将在loadpath
搜索此文件,在这种情况下,从jquery-rails
引擎的vendor/asset/javascripts
目录加载它。