【问题标题】:Cannot set "compile" flag to true when using custom precompilation使用自定义预编译时无法将“编译”标志设置为 true
【发布时间】:2015-01-24 02:47:52
【问题描述】:

我在安装 angulartics 模块后遇到了这里描述的问题:

https://github.com/sstephenson/sprockets/issues/347#issuecomment-25543201

我使用建议的解决方案来更改预编译的文件,以便不包含 LICENSE 文件:

# We don't want the default of everything that isn't js or css, because it pulls too many things in
config.assets.precompile.shift

# Explicitly register the extensions we are interested in compiling
config.assets.precompile.push(Proc.new do |path|
  File.extname(path).in? %w(.html .erb .haml .png .gif .jpg .jpeg .eot .otf .svc .woff .ttf)
end)

而且它确实有效……有点。问题是我需要在 production.rb 文件中将编译标志设置为 true,这会大大降低网站速度,尤其是在第一次加载时:

config.assets.compile = true

如果我尝试在生产中坚持默认的“false”,每次尝试提供任何 css 或 js 代码时都会出错:

Nov 25 14:18:18 <...> app/web.1:  ActionController::RoutingError (No route matches [GET] "/stylesheets/sessions.css"): 
Nov 25 14:18:18 <...> app/web.1:    vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
...

为什么会这样?在避免 LICENSE 文件编译的同时,我能做些什么来修复它?还是我必须选择我的毒药?

谢谢。

【问题讨论】:

    标签: ruby-on-rails asset-pipeline sprockets precompile


    【解决方案1】:

    结果我把对 config.assets.precompile 的更改放在 application.rb 中,而它应该放在 production.rb 中。呸。足够简单的修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-18
      • 2015-10-02
      相关资源
      最近更新 更多