error precompiling assets when moving to production

帅比萌擦擦* 提交于 2019-12-03 21:43:57

Found this issue while researching: https://github.com/rails/sass-rails/issues/368. Apparently, you'll have to check each file to find out which one is failing to compile.

But you can create a rake task to help with the process:

Just add the following code to a lib/tasks/assets.rake file

namespace :assets do

  desc "Find Sass::SyntaxError files..."
  task find_scss_with_error: :environment do
    files = Dir.glob( Rails.root.join("app", "assets", "stylesheets", "**/*")).grep(/.*\.[css|scss]/)
    files.each do |file|
        print "Trying to compile #{file}..."
        template = File.read(file)
        sass_engine = Sass::Engine.new(template)
        begin
            sass_engine.render
            print "[OK]"
        rescue
            print "[ERROR]"
        end
        puts
    end
  end

end

and run

rake assets:find_scss_with_error

Results:

Trying to compile /data/ruby/scss-comments-failure/app/assets/stylesheets/example.css...[ERROR]
Trying to compile /data/ruby/scss-comments-failure/app/assets/stylesheets/application.css...[OK]

Some notes:

  • It'll check for *.css and *.scss files, including subdirectories.
  • The script will not output compression to file. It's just a in-memory test.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!