加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Heroku在部署时不会预编译资产

发布时间:2020-12-17 01:52:42 所属栏目:百科 来源:网络整理
导读:它在文档中非常明确地说如果我不在本地预编译它就会这样做. 说实话,我没兴趣在本地预编译这些. 我在production.rb中有什么,我在application.rb中重复了一遍 在我的production.rb中: config.serve_static_assets = falseconfig.assets.compile = falseconfig
它在文档中非常明确地说如果我不在本地预编译它就会这样做.

说实话,我没兴趣在本地预编译这些.

我在production.rb中有什么,我在application.rb中重复了一遍

在我的production.rb中:

config.serve_static_assets = false
config.assets.compile = false

config.assets.precompile << 'application.js'
config.assets.precompile << 'application.css'
config.assets.precompile << 'screen.css'

然后我部署,然后返回:

-----> Compiled slug size: 52.4MB
-----> Launching... done,v28
       http://myapp.herokuapp.com deployed to Heroku

所以它“编译”了一些东西,对吗?除了没有,我去网站,.css和.js文件是空白的.

为了在本地预编译,我需要在bootstraps_and_overrides.css中注释掉该行:

@import "screen.css.scss";

然后它在本地预编译,我的本地机器将无法正确加载css,但远程它将实际正常工作.

所以我现在的部署方法是注释掉那行代码,

bundle exec rake assets:precompile
git add .
git commit -m "Adding public/assets"
git push heroku development:master

然后(不幸的是!):

bundle exec rake assets:clean

然后在我的.css中取消注释该行代码.

解决方法

有些事要检查

>你在雪松上,对吧? Heroku仅在Cedar上支持此行为.
>你在Rails 3上,对吗? Heroku doesn’t support precompiling assets on Rails 4.
>你打开了资产管道,对吗?在config / application.rb中,您需要行config.assets.enabled = true
>您必须没有公共/资产文件夹. On deployment Heroku decides whether or not to precompile based on whether this folder is present (even if it’s empty).>如果管道已打开且您没有assets文件夹,则预编译必须失败.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读