Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What sprockets mean in rails

So, I just realised that I have absolutely no Idea what Sprockets are in rails.

when using either bootstrap, or materialize, it is requested to include the sprocket (bootstrap-sprocket or materialize-sprocket) in the application.js file.

Everything I search talks about the asset pipeline and confuses me the more.

According to ruby-guides,

The asset pipeline is technically no longer a core feature of Rails 4, it has been extracted out of the framework into the sprockets-rails gem.

and when I did bundle show sprockets-rails, I got:

/Users/Sunday/workspace/resilience/vendor/bundle/ruby/2.1.0/gems/sprockets-rails-2.3.1 

which shows that I have the gem, at least.

But my confusion and my question is that what is the importance of sprockets, as opposed to sprockets-rails that made other gems like bootstrap and materialize and probably some others to have sprockets, especially in their javascript files?

Thanks.

like image 727
x6iae Avatar asked Aug 05 '15 09:08

x6iae


People also ask

What are sprockets Ruby?

Sprockets is a Ruby library for compiling and serving web assets. It features declarative dependency management for JavaScript and CSS assets, as well as a powerful preprocessor pipeline that allows you to write assets in languages like CoffeeScript, Sass and SCSS.

What is sprockets gem?

Sprockets is a Rack-based asset packaging system that concatenates and serves JavaScript, CoffeeScript, CSS, LESS, Sass, and SCSS.

How do you Precompile in rails?

This method is responsible for saving assets to disk, and is pretty self-explanatory. Run rake assets:precompile from the command-line from the root of your Rails application. Look at the public/assets directory and you'll see the assets of your Rails application. Our interest at this point is rails.


1 Answers

Sprockets is a Ruby library for compiling and serving web assets. Sprockets allows to organize an application’s JavaScript files into smaller more manageable chunks that can be distributed over a number of directories and files. It provides structure and practices on how to include assets in our projects.

Using directives at the start of each JavaScript file, Sprockets can determine which files a JavaScript file depends on. When it comes to deploying your application, Sprockets then uses these directives to turn your multiple JavaScript files into a single file for better performance.

like image 135
Sooraj Chandu Avatar answered Oct 12 '22 08:10

Sooraj Chandu