seifeslimene
seifeslimene

Reputation: 113

How Sprocket's require works?

I have a file called application.js under app/assets/javascripts

// = require libs/jquery-retina
// = require libs/jquery.popupoverlay
// = require libs/messg

// = require site_logic/application
// = require serviceworker-companion

// = require i18n
// = require i18n-rules
// = require lazysizes.min

i18n is actually is a gem that I already installed and I don't have any i18n file in the same folder as the application.js file is in and I already saw in the browser that the file was successfully got concatenated to application.js

I wonder how is that possible? because normally the file should be in the same directory.

Upvotes: 2

Views: 848

Answers (1)

max
max

Reputation: 101901

Sprockets will look through the paths specified in Rails.application.config.assets.paths which includes app/assets, lib/assets and vendor/assets it also includes any paths added by Rails engines.

Assets within an engine work in an identical way to a full application. Because the engine class inherits from Rails::Engine, the application will know to look up assets in the engine's app/assets and lib/assets directories.

The gems you are using are written as engines, and are mounted when they are required by Bundler.require(*Rails.groups) in config/application.rb.

See:

Upvotes: 1

Related Questions