在Rails生产中禁用资产缩减 [英] Disable Asset Minification in Rails Production

查看:98
本文介绍了在Rails生产中禁用资产缩减的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在我的heroku生产环境中调试javascript,我需要禁用资源压缩(或至少压缩javascript)。我尝试了 config.assets.compress = false 以及 config.assets.debug = true ,压缩资产仍然使用。然后,我删除了压缩资产,此时没有呈现任何资产。我添加了 config.assets.enabled = false ,这没有帮助。我试图将未压缩的资产复制到各种目录,包括应用程序根,公共和公共/资产(后两个使用文件夹images,javascripts和stylesheets,并将资产直接放入文件夹我最终能够通过改变html来直接引用所有的javascript文件,但CSS和图像仍然不工作。

In order to debug javascript in my heroku production environment, I need to disable asset compression (or at least compression of javascript). I tried config.assets.compress = false along with config.assets.debug = true, and the compressed assets were still used. I then deleted the compressed assets, at which point no assets were rendered at all. I added config.assets.enabled = false, which did not help. I tried copying the uncompressed assets into various directories, including the application root, public, and public/assets (the latter two using both the folders "images, "javascripts", and "stylesheets", and putting the assets directly into the folders without the three subfolders). I was eventually able to get the javascripts to work by changing the html to directly reference all of the javascript files. But the CSS and images still are not working.

我会认为我的原始 config.assets.compress = false 应该有效。任何想法我做错了什么?

I would have thought that my original config.assets.compress = false should have worked. Any ideas what I did wrong?

推荐答案

我读了文档

创建一个不压缩js / css的模块: lib / modules / no_compression.rb

create a module that does nothing to compress js / css here: lib/modules/no_compression.rb

class NoCompression
  def compress(string)
    # do nothing
    string
  end
end

用您的无用压缩器压缩

config.assets.compress = true
config.assets.js_compressor = NoCompression.new
config.assets.css_compressor = NoCompression.new

这篇关于在Rails生产中禁用资产缩减的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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