Rails 4: Invalid CSS 生产模式资产预编译错误

Rails 4: Invalid CSS error during asset precompile in production mode

我对资产预编译有疑问。当我尝试使用以下方式为生产模式预编译资产时:

RAILS_ENV=production bundle exec rake assets:precompile

出现此错误:

DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block in tsort_each at /usr/local/lib/ruby/2.2.0/tsort.rb:226)
I, [2016-06-15T18:06:55.828561 #19627]  INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/bootstrap.min-f3ab05f17df205c2d2a559852b8609eaa090ea127ff142bfb6ebf090ee187fd4.css
I, [2016-06-15T18:06:55.913275 #19627]  INFO -- : Writing /home/rails/Desktop/hammasir/public/assets/bootstrap.min-f3ab05f17df205c2d2a559852b8609eaa090ea127ff142bfb6ebf090ee187fd4.css.gz
rake aborted!
Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}"
(sass):86
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
zlib(finalizer): Zlib::GzipWriter object must be closed explicitly.
zlib(finalizer): the stream was freed prematurely.

其他css个文件也有同样的问题。似乎提到的文件没问题,没有遗漏 } 或 ; .此外,所有这些文件都是众所周知的 css 文件,例如 bootstrap!我用不同的 css 调试器检查了这些文件,结果不同。一次没有任何错误只是一些警告,一次在多行中出现类似错误:

Sorry, the at-rule @-webkit-keyframes is not implemented. 

如果您对此问题有解决方案,请告诉我。

此外,我在Heroku上部署了我的应用程序,并尝试在部署成功后添加这些文件。不幸的是,这些文件导致我的应用程序崩溃。所以,我想我应该想办法在生产模式下成功预编译它们。

因为找到了答案,所以写在这里,希望对其他人有用。

要解决弃用警告,请检查此 link:

关于错误,你应该找到具体是哪个文件导致了错误。生成的错误和其中提到的文件具有误导性。

您可以使用您的 assets.rb 文件来查找哪个文件(文件)包含语法错误。评论或删除 assets.rb 中的所有引用文件,但在生产模式下重做资产预编译命令除外:

RAILS_ENV=production bundle exec rake assets:precompile

并对所有 css 个文件重复此操作,以了解哪个包含错误。这次此命令的输出会有所帮助,并准确地指出问题所在。然后,很容易找到错误并修复它。