Skip to content

Commit

Permalink
use terser instead of uglifier
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickpatrickpatrick committed Nov 9, 2023
1 parent 4b055f5 commit a26bbca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ gem "sassc-rails"
gem "slimmer"
gem "sprockets-rails"
gem "uglifier"
gem "terser"

group :test do
gem "cucumber-rails", require: false
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ DEPENDENCIES
simplecov-rcov
slimmer
sprockets-rails
terser
timecop
uglifier
unparser
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?

# Compress JavaScript.
config.assets.js_compressor = :uglifier
config.assets.js_compressor = :terser

# Compress CSS using a preprocessor.
# config.assets.css_compressor = :sass
Expand Down
17 changes: 17 additions & 0 deletions config/initializers/sprockets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This adds terser as a recognised compressor
# to Sprockets. Without this patch, Sprockets
# will not be able to run terser.
#
# Code originates from:
# https://stackoverflow.com/a/70086366

require "terser"

module Sprockets
class Environment < Base
def js_compressor=(compressor)
register_compressor "application/javascript", :terser, Terser::Compressor
super
end
end
end

0 comments on commit a26bbca

Please sign in to comment.