asset pre compilation for subdirectory manifest file

核能气质少年 提交于 2019-12-06 21:49:37

问题


I am using Rails 3.1 and under assets I have files like this:

assets
  javascripts
    admin
        admin.js
        a1.js
    client
       client.js
        c1.js

admin.js looks like this

//
//= require jquery
//= require jquery_ujs
//= require a1

client.js looks like this

//
//= require jquery
//= require c1

Everything works fine in development mode. When I do rake assets:precompile then I do not see any javascript files in public/assets. I do see all the stylesheets in public/assets.

I think this has to do with the fact that manifest files (admin.js and client.js) in this case are in subdirectory.

So is this true that rake assets:precompile does not look into subdirectories?

Any suggestions on how to fix this. I prefer to have the files the way I laid out because I have a bunch of javascript files.


回答1:


There is a precompile array in the Rails config that sets what files to precompile. application.js and application.css in any directory.

You will need to add your files to the precompile array:

config.assets.precompile += ['admin/admin.js', 'client/client.js']

And they should be accessible via:

javascript_include_tag "admin/admin.js"

and

javascript_include_tag "client/client.js"



回答2:


At rails 3.2.6, when managing javascript assets in subdirs, you can name the manifest for each subdir 'index.js' (as opposed to OP's 'admin.js' and 'client.js'), and then in config/environments/production.rb say:

config.assets.precompile += ['admin.js', 'client.js']

Magic behind the scenes will look in the admin subdir and compile according to the specs in index.js, outputting to admin.js; likewise for client.

The assets will then be accessible via:

javascript_include_tag 'admin'


来源:https://stackoverflow.com/questions/8305585/asset-pre-compilation-for-subdirectory-manifest-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!