Rails资产管道和javascript文件-维护换行符以帮助调试 [英] Rails asset pipeline and javascript files - maintaining line breaks to aid debugging

查看:82
本文介绍了Rails资产管道和javascript文件-维护换行符以帮助调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从 Jammit 迁移到了

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

但是,我最近开始在生产中遇到一些脚本错误,意识到我几乎无法调试它们.之前,我已将Jammit配置为保留换行符,但否则请删除javascript文件中的所有空白.这是为了确保如果我看到运行时错误,就能找到有问题的行并希望找出问题所在.使用Rails Asset Pipeline和默认的:uglifier压缩器,似乎删除了所有空格,包括换行符,因此我的脚本错误无法告诉我问题出在哪里.

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.

是否有人知道如何配置Rails Asset Pipeline以保留换行符以便可以调试代码?

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

马特

推荐答案

在您的production.rb中设置:

config.assets.compress = false

并运行rake assets:precompile不会破坏您的资产.

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

此处提供了更多选项: https://github.com/lautis/uglifier .

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

这篇关于Rails资产管道和javascript文件-维护换行符以帮助调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆