Rails 3.1 asset pipeline and manually ordered Javascript requires

前端 未结 5 1983
余生分开走
余生分开走 2020-11-29 01:01

I am trying to convert an existing app to the new 3.1 asset pipeline layout, and want to include a lot of vendor files that have to be in a specific order, (underscore.js an

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 01:25

    require_tree does exactly what you tell it. If you give it

    //= require_tree .
    

    it loads the files in the current directory where require_tree is called. If you give it

    //=require_tree ../../../vendor/assets/javascripts
    

    then you'll get the javascript under vendor.

    I did not like the ../../.. notation, so I created a file called vendor/assets/javascripts/vendor_application.js which contains:

    //= require_tree .
    

    That loads the javascript under the vendor directory.

    Note, require does search the 3 pipeline locations (app, lib, vendor) for the file to require. require_tree is literal, which is probably the way it should be.

    The railscast on this is very helpful: http://railscasts.com/episodes/279-understanding-the-asset-pipeline

提交回复
热议问题