Application.css 未在生产环境中使用 heroku 进行更新

Application.css not updating in production with heroku

当我推送到 heroku 时,我的 application.css 没有改变。

rake assets:precompile # does some things
git add-commit -m "..."
git push heroku master

Application.css:

*
*= require foundation_and_overrides
* required other files
*/

body {
 background: red
}

生产环境:

config.assets.compile = true
config.assets.digest = true

没有任何效果,我的背景即使设置为红色也是白色的。管道如何与 heroku 和 rails 5 配合使用?

您需要 运行 bundle exec rake assets:precompile RAILS_ENV=production 否则它将使用您的开发环境配置设置进行预编译。此外,为了强制更改指纹摘要,我希望您在 application.css 文件的最顶部添加注释,使其看起来像这样:

/assets/stylesheets/application.css
/* Adding a comment to force a new digest and expire cached assets in browsers */

此外,请确保在您的 gem 文件中包含用于服务资产的 heroku gem:

gem 'rails_12factor', group: :production

此外,作为旁注,您要求在设置 config.assets.compile = true

时性能大幅下降

在部署到生产环境并保持 assets.compile=false

之前,您应该确保找到任何丢失的资产并修复资产路径