Rails 3.1 资产预编译 - 包括所有 javascript 文件 [英] Rails 3.1 asset precompilation - include all javascript files

查看:29
本文介绍了Rails 3.1 资产预编译 - 包括所有 javascript 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 Rails 3.1 为预编译挑选更多的资源.特别是,编译文件的默认匹配器不会从 vendor/assets/javascripts 添加 .js 文件.我可以将资产添加到 config.assets.precompile 列表中,但这似乎很烦人.我不想在 application.js 清单中引用它们,因为我不希望它们包含在所有页面中.

I want Rails 3.1 to pick up more of my assets for precompilation. In particular, the default matcher for compiling files doesn't add .js files from vendor/assets/javascripts. I can just add the assets to the config.assets.precompile list, but this seems annoying. I don't want to refer to them in the application.js manifest, because I don't want them included in all pages.

总而言之,任何请求在 vendor/assets/javascripts 中找到的所有 .js 文件都被 rake assets:precompile 预编译的方法,但没有将它们包含在所有页面中?

In summary, any way to request that all .js files found in vendor/assets/javascripts get precompiled by rake assets:precompile, but without having them included in all pages?

推荐答案

config.assets.precompile 接受正则表达式和通配符匹配 - 所以要确保所有 js文件得到编译,没有按名称指定每个,这样的事情应该可以解决问题:

config.assets.precompile accepts regular expressions and wildcard matching - so to ensure all js files get compiled, without specifying each by name, something like this should do the trick:

config.assets.precompile << '*.js'

这篇关于Rails 3.1 资产预编译 - 包括所有 javascript 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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