【问题标题】:Asset pipeline not compressing javascripts into application.js资产管道未将 javascripts 压缩到 application.js
【发布时间】:2011-10-17 18:41:11
【问题描述】:

我有两个问题。

  1. 我是否错误地假设我的所有 javascripts 都应该在 rails 3.1 中默认压缩到 application.js 中,即使在开发模式下也是如此?

  2. 如果不是,那为什么我的标签有我所有的 30 个 javascript 并且需要永远加载?

我的 application.js 文件如下所示:

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .

并在浏览器中呈现为:

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file. 
//
;

虽然我所有的其他 javascript 都已完整呈现。

非常感谢!

【问题讨论】:

    标签: ruby-on-rails-3.1 asset-pipeline


    【解决方案1】:

    如果这是一个新的 Rails 应用程序,调试模式默认开启。调试模式告诉 Sprockets 将每个文件的标签写入 HTML 源代码。这样做是为了方便源文件调试。

    如果您只想让一个文件处于开发模式,请转到您的 development.rb 并设置:

    config.assets.debug = false

    这将为每个清单提供一个文件。

    压缩在开发中默认是不开启的,但如果你也想要,那么设置:

    config.assets.compress = true

    您需要将压缩器选项从 production.rb 移动到 application.rb,以便开发环境可以访问它们。

    我在开发模式下关闭了调试,但我不使用压缩,因为处理文件需要额外的时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-27
      • 1970-01-01
      • 2019-09-18
      • 1970-01-01
      • 2013-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多