How disable assets compilation on heroku?

妖精的绣舞 提交于 2019-12-23 16:25:47

问题


I'm trying to deploy my rails app to heroku using this turtorial:

https://devcenter.heroku.com/articles/getting-started-with-rails4

So, I use rails 4.1.1 and ruby 2.1.1

My Gemfile has gem 'rails_12factor', group: :production inside.

My application.rb:


require File.expand_path('../boot', __FILE__)

require 'rails/all'

Bundler.require(*Rails.groups)

module Charticus
  class Application  Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
  end
end

I created file public/assets/manifest.yml

But when I deploy app to heroku - it compile all my js-files files to application.js and all css-files application.css. And I can't see it on app.heroku.com using firebug.

What I need to do with my configurations to see all my js and css files on app.heroku.com ? How disable assets precompiling and minification on heroku?

Help me please! Thanks


回答1:


lib/tasks/assets.rake

Rake::Task["assets:precompile"].clear
   namespace :assets do
     task 'precompile' do
     puts "Not pre-compiling assets..."
   end
end

You are done.




回答2:


I compare config/environments/development.rb and config/environments/production.rb.

And make production.rb asset configs like in development.rb:

Comment this lines:

  • config.serve_static_assets = false
  • config.assets.js_compressor = :uglifier
  • config.assets.compile = false
  • config.assets.digest = true

Then:

  1. Push my changes to git repo git push origin master
  2. Push changes to heroku git push heroku master



回答3:


Rails 4 applications have a manifest-*.json file, not a manifest.yml file. This file is typically generated when you run rake assets:precompile , how are you compiling your assets?

Regardless, you need a file public/assets/manifest-(fingerprint).json file




回答4:


Fast forward to 2018, and you would need to add the following to config/initializers/production.rb:

config.assets.enabled = false

Then you'd need to customize Heroku's Ruby Buildpack to not run the assets:precompile rake task. I won't provide a link to such a buildpack because I won't support or warrant one, but its pretty easy to find it in lib/language_pack/ruby.rb and start removing relevant code.

You'd then have to configure your Heroku app to use your new forked Buildpack instead of the default one (e.g. using heroku buildpacks).

Thats the cleanest way to disable the asset pipeline in a Heroku app w/ Rails, without resorting to overriding Rails' built-in rake tasks.



来源:https://stackoverflow.com/questions/23687972/how-disable-assets-compilation-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!