子目录清单文件的资产预编译 [英] asset pre compilation for subdirectory manifest file

查看:74
本文介绍了子目录清单文件的资产预编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3.1,并且在资产下我有这样的文件:

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看起来像这样

admin.js looks like this

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

client.js看起来像这样

client.js looks like this

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

在开发模式下一切正常.当我执行Assets:precompile时,我在公共/资产中看不到任何javascript文件.我确实在公共/资产中看到了所有样式表.

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.

我认为这与清单文件(admin.js和client.js)在此子目录中有关.

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

那么rake asset:precompile不会查看子目录是真的吗?

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

有关如何解决此问题的任何建议.我更喜欢按我的布局方式放置文件,因为我有一堆JavaScript文件.

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.

推荐答案

Rails配置中有一个预编译数组,用于设置要预编译的文件. 任何目录中的application.js和application.css.

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"


javascript_include_tag "client/client.js"

这篇关于子目录清单文件的资产预编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆