Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
854 views
in Technique[技术] by (71.8m points)

ruby on rails - put /assets in .slugignore for Heroku deployments with asset_sync (S3/CDN)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...