Rails 3.1 和 sprockets 使使用 firebug 进行调试变得更加困难?
在 Rails 3.1 中,Sprocket 用于管理资源并将它们打包到单个文件中。一般来说,这并不是一个坏主意。
正如外部来源引用的那样,它解释了当前的问题:
这种方法的一个问题是 它可能会使调试变得更加困难,如果你 必须看看“串联”CSS 生产中的文件有意义 包含什么代码,不包含什么代码,它是 更难知道什么来自哪里 比你只包含原来的 源代码文件。
一个解决方案是有办法 在“串联”和“串联”之间切换 轻松“正常”模式(也许是 已经可能了,我不知道),所以 正常的发展应该是 畅通。但你必须求助于 大的串联文件 生产中的调试。
在 Rails 3.0.X 中,我们的设计人员可以使用 Firebug 轻松定位 CSS 设置,Firebug 会直接指示文件和行号,因为所有 CSS 文件都是独立的,没有打包成一个。
或者我错过了重点?
In Rails 3.1, Sprockets are used to manage assets and package them into a single file. Which, in general, is not such a bad idea.
As quoted from an external source, which explains the issue at hand:
A problem with this approach is that
it could make debugging harder, if you
have to look at the "concatenated" CSS
file in production to make sense of
what code's included and not, it's
harder to know what comes from where
than if you just included the original
source code files.One solution would be to have a way to
switch between "concatenated" and
"normal" modes easily (maybe it's
already possible, I don't know), so
that normal development would be
unimpeded. But you'd have to resort to
the big concatenated file for
debugging in production.
In Rails 3.0.X, our designer could easily pin-point the CSS setting using Firebug, which will indicate the file and line number directly, since all CSS files were separate and not packaged into one.
Or am I missing the point?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您还可以使用:
这些文件在开发中不会串联,但在其他环境中会串联。
You can also use :
The files will not be concatenated in development but will in other environments.
将 ?debug_assets=true 添加到要调试的任何 URL。它将资产分成各个部分。如果没有它,串联将根据您的环境设置进行。
Add ?debug_assets=true to any URL you want to debug. It splits the assets into their parts. Without it, concatenation happens according to your environment settings.
我认为最终(当 RC 接近/成为版本时)您将能够使用以下内容修改您的 config/application.rb
config.assets.css_compressor = false
但是,atm,这并不能真正解决这个问题,因为 stylesheet_asset_tag 辅助函数与新管道不完全兼容,并且 :all 修饰符不起作用,所以......
在你的
application.html.erb
视图,您将必须链接每个 css只要您的
config/application.rb
config.assets.enabled = true > 资产的根目录将是(默认情况下)/assets
您可以启动 Rails 控制台 (
rails c
) 和p Rails.application.assets 查看同时可配置的属性。
我同意这不是最好的解决方案,但在这一点上(使用 RC 与稳定版本)这是我发现的最好的方法。
更新:挖掘边缘API,发现这个ActionView::Helper
sprockets_stylesheet_link_tag
(http://edgeapi.rubyonrails.org/classes/ActionView/Helpers/SprocketsHelper.html)但它似乎仍然是 stylesheet_link_tag 的不完整替代品,因为它不支持:all
并且您仍然必须在函数调用中包含stylesheets/
段。话虽如此,它可能是继续使用的功能,所以......I think in the end (when the RC gets closer/becomes a release) you will be able to modify your
config/application.rb
with the followingconfig.assets.css_compressor = false
But, atm, that doesn't really fix it since the stylesheet_asset_tag helper function isn't exactly compatible with the new pipeline and the :all modifier doesn't work, so...
In your
application.html.erb
view you will have to link each cssAs long as you have
config.assets.enabled = true
in yourconfig/application.rb
the root of assets will be (by default)/assets
You can fire up a rails console (
rails c
) andp Rails.application.assets
to see the properties that are configurable in the mean time.I agree not the best solution, but at this point (using an RC vs a stable release) its the best way I've found.
UPDATE: Digging around the edge api, found this ActionView::Helper
sprockets_stylesheet_link_tag
(http://edgeapi.rubyonrails.org/classes/ActionView/Helpers/SprocketsHelper.html) but it seems to be still an incomplete replacement for stylesheet_link_tag since it doesn't support:all
and you still have to have thestylesheets/
segment in your function call. With that said, its prolly the function to use moving forward, so...您还可以使用:
它将在浏览器的查看源代码中为您提供以下输出
You can also use :
It Will gives you following output in view source of your browser
我发现了一个有趣的问题。如果我预编译资产(提交到 git 中),在生产模式下进行测试,然后返回到在同一台计算机上使用开发环境,我就会看到这个问题。
即使我回到开发模式,公共/资产的内容也会被缓存和提供,而不是新的资产内容。所以这是我修复它的方法:
I found an interesting issue. If I precompile assets (to commit into git), test in production mode, and then go back to using a development environment on the same machine, I see this problem.
Even though I'm back in development mode, the contents of public/assets are being cached and served instead of fresh asset contents. So here's how I fixed it:
sprockets 可能只能在生产环境中工作,在开发和测试期间无需将所有内容打包到单个文件中
sprockets probably will work only in production environment, there's no need to package everything into a single file during development and test