Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails asset pipeline and javascript files - maintaining line breaks to aid debugging

I recently migrated from Jammit to the Rails Asset Pipeline. Other than a few teething issues, everything has been working well.

However, I recently started getting some script errors in production, and realised that it's near on impossible for me to debug them. I had previously configured Jammit to retain linebreaks, but otherwise remove all white space in the javascript files. This was to ensure that should I see a runtime error, I would be able to locate the offending line and hopefully figure out what the problem is. With the Rails Asset Pipeline, and the default :uglifier compressor, it appears all whitespace is removed including line breaks, and as such my script errors do not tell me where in the code the problem was.

Does anyone know anyway to configure the Rails Asset Pipeline to retain line breaks so that code can be debugged?

Matt

like image 590
Matthew O'Riordan Avatar asked Apr 24 '12 12:04

Matthew O'Riordan


1 Answers

Set in you production.rb:

config.assets.compress = false

and running rake assets:precompile won't uglify your assets.

UPD:

So-called compression means (among other stuff): remove line breaks and comments. But if you want to obfuscate your variables and save some readability then use:

# in production.rb
config.assets.compress = true
config.assets.js_compressor = Uglifier.new(:beautify => true) if defined? Uglifier

Here see for more options: https://github.com/lautis/uglifier.

like image 197
jdoe Avatar answered Sep 25 '22 18:09

jdoe