Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 Sprockets require directives - is there a way to exclude particular files?

If I'm using //=require_tree . in application.css, is there a way to exclude particular files other than resorting to //=require_directory and tree organization?

Perhaps something like //= require_tree ., {except: 'something'}

like image 483
tamersalama Avatar asked Sep 29 '11 19:09

tamersalama


2 Answers

This is possible with Sprocket's new stub directive which is available in Sprockets v2.2.0 and up. However, Rails 3.2 will only ever use Sprockets v2.1.3 which does not have this feature. As of now, the current Edge Rails has the stub directive and it will officially be in Rails 4.0 and above.

Usage:

//= require jquery //= require_tree . //= stub unwanted_js 

stub directives can not be overridden by subsequent require or include directives.

If you want to use the stub directive in your Rails 3.2 project you will have to switch to Edge Rails, or branch your Rails gem with its Sprockets dependency modified to version 2.2.0.

like image 109
Joseph Ravenwolfe Avatar answered Sep 21 '22 16:09

Joseph Ravenwolfe


Since the release of rails 3.2.9, it has support to lock the sprockets to version 2.2.x so that we can use the //= stub directive that latest sprockets have.

//= stub unwanted_js 

http://weblog.rubyonrails.org/2012/11/12/ann-rails-3-2-9-has-been-released/

So, to use it, just upgrade to Rails 3.2.9

like image 45
Autodidact Avatar answered Sep 19 '22 16:09

Autodidact