【问题标题】:Automatically precompile assets before pushing to Heroku在推送到 Heroku 之前自动预编译资产
【发布时间】:2012-01-06 14:48:18
【问题描述】:

在发布到 Heroku 之前,是否可以在 Rails 应用程序中自动预编译我的资产?我总是忘记这样做,所以如果我输入git push heroku master 时,它会先运行rake assets:precompile ; git commit add . ; git commit -a -m "Precompile.",或者类似的东西。

有没有人实现过这样的解决方案?可能没有钩子?虽然我怀疑这是唯一的方法。

【问题讨论】:

    标签: ruby-on-rails ruby heroku rake


    【解决方案1】:

    我终于想通了。我确实在雪松堆栈上。问题是我已经将public 目录检查到Git 中,当我推送到Heroku 时,它意识到public 存在,因此假设我进行了预编译。运行git rm -r public 并将public/** 添加到我的.gitignore,然后推送,即可解决问题。

    【讨论】:

      【解决方案2】:

      听起来你可能不在Heroku's Cedar Stack 上?如果您使用资产管道 (Rails -v >= 3.1),cedar 提供 three options 用于编译资产。

      来自docs

      如果您没有在本地编译资产,我们将尝试运行 assets:precompile slug 编译期间的任务。

      【讨论】:

        【解决方案3】:

        您始终可以在 bash 个人资料中为 heroku 或类似 rake assets:precompile ; git commit add . ; git commit -a -m "Precompile." ; git push heroku master 的别名添加别名 即

        #in ~/.bash_profile 
        alias precompile_push='rake assets:precompile ; git commit add . ; git commit -a -m "Precompile." ; git push heroku master'
        

        【讨论】:

        • 如果这是您部署过程的一部分,我建议您在代码库中创建一个脚本。
        【解决方案4】:

        在 cedar 堆栈上,它将在 slug 编译期间执行此操作。我建议这样做。

        【讨论】:

          【解决方案5】:

          我创建了一个 gem,它作为守护进程运行,并自动从 Git 存储库中提取更改、预编译资产、提交和推回。

          https://github.com/nectify/rails-precompile2git/

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2016-05-12
            • 1970-01-01
            • 1970-01-01
            • 2012-07-11
            • 2021-08-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多