Search code examples
ruby-on-railsrubyrubygemssprocketsmiddleman

Requiring a file from a required file in Sprockets


I would like to require a javascript file that itself requires other javascript files:

In main.js

//= require plugins

... Shared Code

In plugins.js

//= require vendor/handlebars-1.0.rc.1.js
//= require vendor/jquery.animate-colors-min.js
//= require vendor/spin.min.js

However although sprockets adds the contents of plugins.js to main.js, it doesn't seem to evaluate the requires within it, so they are included as comments in the compiled main.js rather than it pulling in the js files and including them.

In the compiled main.js

//= require vendor/handlebars-1.0.rc.1.js
//= require vendor/jquery.animate-colors-min.js
//= require vendor/spin.min.js

...Shared Code

If I add these requires into main.js rather than plugins.js, they are propprly required and their contents is included in the compiled main.js

So why isn't sprockets evaluating the includes in plugins.js?


Solution

  • You should place your //= directives at the top of plugins.js