zf7r4a
Last Updated: February 25, 2016
·
624
· antage

Eliminate javascript debug code after assets compiling (Rails 4 only)

Uglifier is able to eliminate unreachable code, so we can get rid of any 'console.log' lines after assets compiling.

app/assets/javascripts/application.js:

if (typeof DEBUG === "undefined")
    DEBUG = true;

if (DEBUG)
    console.log("This is debug message.");

config/environments/production.rb:

config.assets.js_compressor = Uglifier.new(define: { DEBUG: false })
$ RAILS_ENV=production rake assets:clobber assets:precompile
$ find public/assets/ -name "application-*.js" -exec grep console.log {} \; wc -l
0