【问题标题】:how to precompile assets in vendor?如何在供应商中预编译资产?
【发布时间】:2014-02-04 15:29:02
【问题描述】:

在生产中我收到此错误:

ActionView::Template::Error (vendor/jquery_extras.js isn't precompiled):
    26: = stylesheet_link_tag "application", media: "all"
    27: = javascript_include_tag "application"
    28: 
    29: = javascript_include_tag "vendor/jquery_extras"
    30: = javascript_include_tag "vendor/jquery.ba-bbq"
    31: = javascript_include_tag "vendor/moment-with-langs"
    32: = javascript_include_tag "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"
  app/views/layouts/_headers.html.haml:29:in `_app_views_layouts__headers_html_haml__4249496561736037731_30585640'
  app/views/layouts/application.html.haml:12:in `_app_views_layouts_application_html_haml__4179352970330185641_30563940'
  app/controllers/items_controller.rb:82:in `new'

在我的config/environments/production.rb 我有:

# Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = false

  # Compress JavaScripts and CSS
  # config.assets.compress = true
  config.assets.compress = false

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = false

  # Generate digests for assets URLs
  config.assets.digest = true

  # list of assets that need precompilation in vendor directory
  config.assets.precompile += %w( vendor/jquery_extras.js vendor/jquery.ba-bbq.min.js vendor/moment-with-langs.min.js )

在我的public/assets/ 我有:

$ ls -1 jquery_extras* jquery.ba-bbq* moment-with-langs*
jquery.ba-bbq.min-ad74c9887b7231076917be90512e14c4.js
jquery.ba-bbq.min-ad74c9887b7231076917be90512e14c4.js.gz
jquery.ba-bbq.min.js
jquery.ba-bbq.min.js.gz
jquery_extras-7eb0ce2de6f2553ef84968dc07cec831.js
jquery_extras-7eb0ce2de6f2553ef84968dc07cec831.js.gz
jquery_extras.js
jquery_extras.js.gz
moment-with-langs.min-c30ecb28ae71b4d324d710136a628b14.js
moment-with-langs.min-c30ecb28ae71b4d324d710136a628b14.js.gz
moment-with-langs.min.js
moment-with-langs.min.js.gz

在我的vendor/assets 目录中,我有:

$ ls -1 vendor/assets/
fonts
images
img
javascripts
stylesheets

和:

$ ls -1 vendor/assets/javascripts/
jquery.ba-bbq.min.js
jquery_extras.js
moment-with-langs.min.js

这是我的application.js

//= require jquery
//= require jquery_ujs
//= require arwa
//= require jquery.ui.datepicker
//= require jquery.timepicker
//= require colorbox-rails
//= require twitter/bootstrap
//= require cocoon
//= require arwa
//= require_tree .

我不确定我做错了什么。请你帮助我好吗?

谢谢

【问题讨论】:

  • 您的供应商/资产中有什么?
  • 我在问题中添加了列表。谢谢。
  • 供应商资产中的文件应自动包含在编译中。为什么需要将它添加到预编译列表中?如果你删除它并运行预编译,检查它是否被插入到编译文件中。
  • 我删除了预编译,得到了同样的错误,我从视图文件中删除了vendor/,仍然得到同样的错误。这就是我现在所拥有的:= javascript_include_tag "jquery_extras",它仍在抱怨它没有预编译。
  • 你在你的布局中调用这个吗? javascript_include_tag 'jquery_extras'?如果是这样,请将其删除。它应该已经包含在您的 application.js 文件中

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


【解决方案1】:

Assets precompile Guide比较我发现了这个:

在您的 config/enviroments/production.rb

config.assets.compress = false

guide 中是:

# Compress JavaScripts and CSS
config.assets.compress = true

# Choose the compressors to use
# config.assets.js_compressor  = :uglifier
# config.assets.css_compressor = :yui

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false

# Generate digests for assets URLs.
config.assets.digest = true

# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )

如果你在做本地编译,look up here for do it 然后运行本地编译$ RAILS_ENV=production bundle exec rake assets:precompile

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 2011-11-24
    • 2021-04-27
    • 2011-09-18
    • 1970-01-01
    相关资源
    最近更新 更多