我正在努力将我的项目转移到生产
中
RAILS_ENV=production bundle exec rake assets:precompile
给我一个错误,没有指定它是在哪个文件中.
rake aborted! Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}" (sass):89 /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:1207:in `expected' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:1137:in `expected' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:42:in `parse' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/engine.rb:406:in `_to_tree' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/engine.rb:281:in `render' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sprockets-3.7.1/lib/sprockets/sass_compressor.rb:48:in `call' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sprockets-3.7.1/lib/sprockets/sass_compressor.rb:28:in `call' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'
如何找出错误发生在哪个文件中?即使用--trace也没告诉我.
在研究时发现了这个问题:https://github.com/rails/sass-rails/issues/368.显然,您必须检查每个文件以找出哪个文件无法编译.
但是您可以创建一个rake任务来帮助完成该过程:
只需将以下代码添加到lib/tasks/assets.rake
文件中即可
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
并运行
rake assets:find_scss_with_error
结果:
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]
一些说明:
它将检查*.css
和*.scss
文件,包括子目录.
该脚本不会将压缩输出到文件.这只是一个内存测试.