Rails 3.1 Pipeline - Exclude Javascript File

前端 未结 4 1169
醉话见心
醉话见心 2020-12-05 06:48

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 th

相关标签:
4条回答
  • 2020-12-05 07:24

    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)

    0 讨论(0)
  • 2020-12-05 07:29

    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 讨论(0)
  • 2020-12-05 07:32

    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.

    0 讨论(0)
  • 2020-12-05 07:36

    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.

    0 讨论(0)
提交回复
热议问题