Skip to content

Commit f4db3d7

Browse files
committed
Make the API for compression consistent between JS and CSS. By default, users just need to say whether they want compression or not, and a default will be chosen by a Railtie. In the case of CSS, this default is already chosen by the sass-rails gem.
Users can still explicitly choose a compressor in their application.rb if they have a preference, but will usually want to let plugins choose defaults in their Railties.
1 parent efa9695 commit f4db3d7

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

actionpack/lib/sprockets/railtie.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def self.using_coffee?
3030

3131
ActiveSupport.on_load(:action_view) do
3232
include ::Sprockets::Helpers::RailsHelper
33-
33+
3434
app.assets.context_class.instance_eval do
3535
include ::Sprockets::Helpers::RailsHelper
3636
end
@@ -63,8 +63,12 @@ def asset_environment(app)
6363

6464
env.logger = Rails.logger
6565

66-
env.js_compressor = expand_js_compressor(assets.js_compressor)
67-
env.css_compressor = expand_css_compressor(assets.css_compressor)
66+
if assets.compress
67+
# temporarily hardcode default JS compressor to uglify. Soon, it will work
68+
# the same as SCSS, where a default plugin sets the default.
69+
env.js_compressor = expand_js_compressor(assets.js_compressor || :uglifier)
70+
env.css_compressor = expand_css_compressor(assets.css_compressor)
71+
end
6872

6973
env
7074
end

railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
# Compress JavaScripts and CSS
1515
config.assets.compress = true
1616

17-
# Specify the default JavaScript compressor
18-
config.assets.js_compressor = :uglifier
19-
2017
# Specifies the header that your server uses for sending files
2118
# (comment out if your front-end server doesn't support this)
2219
config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx

0 commit comments

Comments
 (0)