我的 Rails 5 个资产中的 None 个正在生产中缩小

None of my Rails 5 assets are minifying in production

我在 Heroku 上有一个 Rails 5.0.0.1 应用程序,当我在 Chrome 中点击开发人员控制台并打开 CSS 和 JS 文件时,我看不到两者它们已被缩小。这是我在完成 Google 速度测试后首次引起注意的。

这是我的一些设置的样子...

application.js

//= require jquery
//= require jquery_ujs
//= require jquery-ui/autocomplete
//= require bootstrap-sprockets
//= require trix
//= require_tree .

application.scss

//Import bootstrap-sprockets
@import "bootstrap-sprockets";


// Import cerulean variables
@import "bootswatch/flatly/variables";

// Then bootstrap itself
@import "bootstrap";
@import "font-awesome";

// Bootstrap body padding for fixed navbar
/*body { padding-top: 60px; }*/

// And finally bootswatch style itself
@import "bootswatch/flatly/bootswatch";

// Whatever application styles you have go last
@import "overrides";
@import "trip";

我正在使用以下 gem:

gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'bootstrap-sass', '~> 3.3.6'
gem 'bootswatch-rails'
gem 'bootstrap-social-rails'
gem 'bootstrap_form'

我在 production.rb

中设置了以下选项
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

我已经预编译并清理了资产,甚至使用

提高了资产版本
Rails.application.config.assets.version = '1.1'

我什至用 rake assets:clobber

从我的资产文件夹中删除了地狱

现在真的不知道为什么 none 这些资产正在缩小。非常感谢任何帮助。

你的 Gemfile 是什么样子的?丑化者有JavaScript 运行ner吗? therubyracer 经常被使用,我对 mini_racer 及其增强的性能相当满意。

在您的 Gemfile 中:

gem 'mini_racer'

然后 运行 bundle install 并提交。

总结一下我和 OP 对主要 post 的评论的结论,问题不是缩小不起作用,而是缩小后的资产没有被使用。这是因为资产在某一时刻已被预编译为 public/assets 并签入 Git; public,未缩小的资产在被提供时优先于缩小的资产。

然后,解决方案是从 Git 中删除这些工件:

git rm -r public/assets

通常不鼓励将预编译资产检查到版本控制中,尽管这取决于您的部署系统。使用 Heroku,通常不需要。有关详细信息,请参阅 Do you add public/assets in version control?