开发者

Rails 3.1 Pipeline - Exclude Javascript File

I want to exclude a particular javascript file (modernizr) from the pipeline because I want it to load separately.

I want to load Modernizr at the beginning and the rest of my javascript concatenated at the end.

Is there way to do the opposite of a require in the asset开发者_如何学JAVA pipeline in 3.1? ie. an exclude?

Thanks in advance.

Adam.


I chose to keep the sprockets functionality by changing

//= require_tree

to

//= require_directory .

This keeps sprockets auto-loading any files in the same directory, but not in any folders further.

This allowed me to move Modernizr.js to the assets/javascripts/top folder and manually load it at the top with:

<%= javascript_include_tag "top/modernizr" %>

and move

<%= javascript_include_tag "application" %>

To the bottom of my application.html.erb file (above the closing body tag)


I realize this is an old question, but Google sent me here last week so it's not an obsolete question. The answer I found elsewhere was the "stub" directive for sprockets. So something like

//= require-tree .
//= stub Modernizr

This keeps Modernizr.js out of the bundled assets. It can be included with its own tag, à la the original answer.

The Sprockets changelog says "stub" was added in January 2012, so it wouldn't have been available at the time this question was first answered, but I think it's a good answer now.


This is far easier accomplished by going to your config/environments/production.rb file and adding the following line

config.assets.precompile += %w( modernizr.js )

Then when you precompile your assets modernizer will have it's own separate file that you can use in your head.


These answers are outdated. Just move active_admin.css.scss from app/assets/stylesheets to vendor/assets/stylesheets.

Do the same with active_admin.js.coffee (move from app/assets/javascripts to vendor/assets/javascripts).

Your assets will then be loaded when needed, and you won't have to make modifications to applications.js to accommodate active_admin.

This solution is described in this issue. Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜