put /assets in .slugignore for Heroku deployments with asset_sync (S3/CDN)

老子叫甜甜 提交于 2019-11-30 15:23:41

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.

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

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.

Have you read this article? - https://devcenter.heroku.com/articles/cdn-asset-host-rails31

The 'Syncing assets' section seems to indicate that the assets can be precompiled on heroku and then the asset_sync gem will upload them from there to your s3 bucket (as part of the precompile step), the article makes no mention of using .slugignore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!