本文介绍了config.assets.precompile 的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Rails 3.1 中,您必须将要包含在资产预编译中的文件列入白名单.您必须打开 config/environments/production.rb 并明确包含您想要预编译的资产:

In Rails 3.1, you must whitelist files that you want included in asset precompilation. You must open up config/environments/production.rb and explicitly include assets you want precompiled:

config.assets.precompile += ['somestylesheet.css']

如果您不这样做并运行rake assets:precompile,您的资产将不会被复制到 public/assets,并且您的应用程序会引发异常(因此导致 500 错误在生产中)当找不到资产时.

If you don't do this this and you run rake assets:precompile, your asset will not be copied to public/assets, and your app with raise an exception(therefore causing a 500 error in production) when an asset is not found.

为什么需要这样做?为什么不自动预编译所有资产?

Why is this necessary? Why aren't all assets automatically precompiled?

这种当前的方法在部署时会产生额外的代码和压力.将资产列入黑名单/排除资产以便开箱即用不是更容易吗?还有其他人分享这些感受吗?

This current approach creates extra code and stress when deploying. Wouldn't it be easier to blacklist/exclude assets so things worked right out of the box? Anyone else share these feelings?

推荐答案

大多数资产自动包含在资产预编译中.根据资产管道的RoR指南:

Most assets are automatically included in asset precompilation. According to the RoR Guide on the Asset Pipeline:

编译文件的默认匹配器包括application.js、application.css以及所有不以js或css结尾的文件:[/\w+\.(?!js|css).+/,/application.(css|js)$/]

如果您要包含其他资产,则可以使用 config.assets.precompile:

You would use config.assets.precompile if you have additional assets to include:

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

或者你可以覆盖它.

这篇关于config.assets.precompile 的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:52