Rails 3.1 asset pipeline and manually ordered Javascript requires

前端 未结 5 1984
余生分开走
余生分开走 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:10

    You have two possible structure : the first one and the second one. With both following examples, you expose a package at /assets/externals.js. You can javascript_include_tag this package, but you can also require it in your application.js file.

    The first one

    vendor/
    ├── assets
    │   ├── javascripts
    │   │   ├── externals.js
    │   │   ├── modernizr-1.7.js
    │   │   └── underscore-1.1.6.js
    │   └── stylesheets
    └── plugins
    

    The file externals.js contains :

    //= require ./underscore-1.1.6.js
    //= require ./modernizr-1.7.js
    

    The second one

    vendor/
    ├── assets
    │   ├── javascripts
    │   │   └── externals
    │   │       ├── index.js
    │   │       ├── modernizr-1.7.js
    │   │       └── underscore-1.1.6.js
    │   └── stylesheets
    └── plugins
    

    The file index.js contains :

    //= require ./underscore-1.1.6.js
    //= require ./modernizr-1.7.js
    

提交回复
热议问题