【问题标题】:Generating new version of all.js to reflect changes from application.js: how does Rails 3.2.12 compile all.js?生成新版本的 all.js 以反映 application.js 的变化:Rails 3.2.12 如何编译 all.js?
【发布时间】:2019-12-18 00:31:15
【问题描述】:

类似的帖子有thisthisthis,但没有人回答问题。

all.js 如何在 Rails 3.2.12 的生产环境中编译?如下图的 production.rb 文件所示,编译资产被禁用,所以不清楚 all.js 最初是如何生成的。

运行rake assets:precompile 会产生以下错误:

rake 中止!不知道如何构建任务“资产:预编译”(见 可用任务列表 rake --tasks)

根本问题是如何更新 all.js 以反映 application.js 中的最新代码。重启服务器没有帮助,那么是什么触发 all.js 重新编译?

Test::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
    config.cache_classes = true

    # Full error reports are disabled and caching is turned on
    config.consider_all_requests_local       = false
    config.action_controller.perform_caching = true

    # Specifies the header that your server uses for sending files
    config.action_dispatch.x_sendfile_header = "X-Sendfile"

    # For nginx:
    # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

    # If you have no front-end server that supports something like X-Sendfile,
    # just comment this out and Rails will serve the files

    # See everything in the log (default is :info)
    # config.log_level = :debug

    # Use a different logger for distributed setups
    # config.logger = SyslogLogger.new

    # Use a different cache store in production
    # config.cache_store = :mem_cache_store

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

    # Enable serving of images, stylesheets, and javascripts from an asset server
    # config.action_controller.asset_host = "http://assets.example.com"

    # Disable delivery errors, bad email addresses will be ignored
    # config.action_mailer.raise_delivery_errors = false

    # Enable threaded mode
    # config.threadsafe!

    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
    # the I18n.default_locale when a translation can not be found)
    config.i18n.fallbacks = true

    # Send deprecation notices to registered listeners
    config.active_support.deprecation = :notify

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

    # 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

    # Defaults to Rails.root.join("public/assets")
    # config.assets.manifest = YOUR_PATH

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

    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
    # config.force_ssl = true   
end

【问题讨论】:

  • 你试过运行rake assets:precompile 任务吗?我不是 100% 虽然它可以在 rails 3 中使用
  • @arieljuod 是的,它给出了一个错误:rake aborted! Don't know how to build task 'assets:precompile' (See the list of available tasks with rake --tasks)。有什么建议么?感谢您的帮助!
  • 根据 3.2 版指南,它应该使用该命令 guides.rubyonrails.org/v3.2/…
  • 简单的解决方案是将此代码Rails.application.config.assets.precompile += ['all.js'] 放入config/initializers/assets.rb

标签: ruby-on-rails ruby-on-rails-3 rubygems


【解决方案1】:

我们终于能够使用这些(次优的)步骤,使用 application.js 的最新更改来刷新 all.js

  1. 发现安装的 Ruby 与 Rails 3.2.12 不兼容,因此降级到 Ruby 2.1.2。这修复了rake assets:precompile 错误。

  2. 运行以下命令,其中一些可能是多余的,但没有时间隔离所需的最少步骤:

    • bundle exec rake assets:clean
    • bundle exec rake assets:precompile
    • bundle exec rake assets:precompile RAILS_ENV=production
    • rake assets:precompile --trace
    • rake assets:precompile RAILS_ENV=production
    • rm all.js

rm all.js这一步之后神奇地出现了重新生成的all.js,但如果这对其他人不起作用,请记得先备份all.js

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多