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

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

问题描述

为了在我的 heroku 生产环境中调试 javascript,我需要禁用资产压缩(或至少是 javascript 的压缩).我尝试了 config.assets.compress = falseconfig.assets.debug = true ,并且仍然使用压缩资产.然后我删除了压缩的资产,此时根本没有渲染任何资产.我添加了 config.assets.enabled = false,这没有帮助.我尝试将未压缩的资产复制到各种目录中,包括应用程序根目录、公共和公共/资产(后两个同时使用文件夹图像"、javascripts"和样式表",并将资产直接放入文件夹中,而无需三个子文件夹).我最终能够通过将 html 更改为直接引用所有 javascript 文件来使 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

将您的资产配置为(不)使用您的无用压缩器进行压缩

configure your assets to (not) be compressed with your do-nothing compressor

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

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

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