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

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

问题描述

我不确定是否有现有的方法可以做到这一点,但使用asset_sync的想法是资产是从S3或某些CDN(例如cloudfront)提供的,因此不需要成为应用程序段落的一部分。是否有可能在Heroku的.slugignore中拥有/资产,并仍然获得资源:预编译和asset_sync工作?
如果我只是将资产放在.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,它将gzip所有css和js资产,因此我通过脚本删除所有.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.

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

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