将/assets 放在 .slugignore 中,用于使用 asset_sync (S3/CDN) 的 Heroku 部署 [英] put /assets in .slugignore for Heroku deployments with asset_sync (S3/CDN)

查看:15
本文介绍了将/assets 放在 .slugignore 中,用于使用 asset_sync (S3/CDN) 的 Heroku 部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定是否有现有的方法可以做到这一点,但是使用 asset_sync 的想法是资产是从 S3 或某些 CDN(例如 cloudfront)提供的,因此不需要成为应用程序 slug 的一部分.是否有可能在 Heroku 上的 .slugignore 中包含/assets 并且仍然使资产:预编译和资产同步工作?如果我只是将/assets 放在 .slugignore 中,它们不会与摘要一起编译,并且对资产的引用没有指纹,因此不起作用.

I am not sure if there is an existing way to do this but with asset_sync the idea is that assets are served from S3 or some CDN(e.g. cloudfront) thus not needing to be part of the application slug. Is it possible to have /assets in .slugignore on Heroku and still get asset:precompile and asset_sync to work? If I just put /assets in .slugignore, they are not compiled with the digest and references to assets are without the fingerprint and thus don't work.

推荐答案

编辑 .slugignore 在那里不起作用,因为排除文件在 Heroku 上的所有编译步骤之前开始.但是我们需要编译所有这些,将它们移动到 S3,然后才删除它们.

Editing .slugignore don't work there, because excluding files begins before all compilation steps on Heroku. But we need to compile these all, move these to S3 and only after that delete these.

我在我的 Rakefile 中写了一些代码,小脚本,通过扩展过滤器删除所有不可用的文件:

I wrote some code into my Rakefile, small script, that deletes all unusable files by extension filter:

Rake::Task["assets:precompile"].enhance do
    puts 'my assets:precompile hook is started!'
    dir_path = "#{Dir.pwd}/public/sites-fromfuture-net/"
    records = Dir.glob("#{dir_path}**/*")
    records.each do |f|
        if f =~ /.*.png$/ or
                f =~ /.*.jpg$/ or
                f =~ /.*.eot$/ or
                f =~ /.*.svg$/ or
                f =~ /.*.woff$/ or
                f =~ /.*.ttf$/ or
                f =~ /.*.otf$/ or
                f =~ /.*.css$/ or
                f =~ /.*.js$/ or
                f =~ /.*.wav$/ then
            File.delete(f)
        end
    end
    # puts Dir.glob("#{dir_path}**/*")
    puts 'my assets:precompile hook is finished!'
end

还有一件事:我使用了一个 heroku-deflater gem,它对所有 css 和 js 资产进行 gzip,所以我通过脚本删除了所有 .css 和 .js 文件,但不删除 .css.gz 和 .js.gz文件,因为 Rails 资产检查.

And one more thing: I use a heroku-deflater gem, which gzips all css and js assets, so I delete all .css and .js files by script but don't delete .css.gz and .js.gz files, because of rails assets checking.

这篇关于将/assets 放在 .slugignore 中,用于使用 asset_sync (S3/CDN) 的 Heroku 部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆