Rails在生产中预编译资产-与开发中不同

问题描述 投票:2回答:1

我的application.css中有以下内容:

 *= require_self
 *= require styles
 *= require custom
 *= require paggination
 *= require colorbox
 *= require registration
 *= require ../vendor/dark

在开发中,一切正常,但是当我开始生产时,还必须预编译一些其他资产,因为站点在生产中看起来有所不同。

Rails是否还可以预编译资产文件夹中的其他css文件,而不仅仅是此要求? 我在Assets文件夹中还有许多其他CSS。

ruby-on-rails asset-pipeline
1个回答
0
投票

默认情况下,Rails仅预编译application.css如果您需要添加单个的CSS文件,则可能需要在某些页面上使用特定样式,则需要像这样添加它们。

# in config/production.rb
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
config.assets.precompile += %w(frontpage.css login.css)

注意:即使它是一个scss文件,您也只列出css结尾。 然后,您可以在视图文件中引用样式表。

<%= stylesheet_link_tag "frontpage" %>

编辑:当然不要忘记做

bundle exec rake assets:precompile RAILS_ENV=production
© www.soinside.com 2019 - 2024. All rights reserved.