Reputation: 3297
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
Upvotes: 6
Views: 5975
Reputation: 11900
One option is you could disable the asset pipeline:
config.assets.enabled = false
Alternatively, if you don't use the Rails Asset Pipleine (sprockets
, sprockets-rails
) at all, you can remove those gems. That will remove the assets:precompile
Rake task, and Heroku will skip it because it can't find it (source - since Rails 4)
Remove sprockets
and sprockets-rails
to remove the definition of assets:precompile
. The bad news is that there's no way to easily remove just these gems since they come pre-packaged with rails
. And by default rails
requires several gems, including the rake task. However, you can opt to list out rails dependencies by name individually, and you can exclude sprockets
from the list:
require 'rails'
require 'active_record/railtie'
require 'active_storage/engine'
require 'action_controller/railtie'
require 'action_view/railtie'
require 'action_mailer/railtie'
require 'active_job/railtie'
require 'action_cable/engine'
require 'action_mailbox/engine'
# require 'sprockets/railtie' <--- Comment out or remove this
require 'action_text/engine'
require 'rails/test_unit/railtie'
NOTE: As of 7.0.0-alpha3
, sprockets
is automatically excluded. See the commit that removed sprockets
, from DHH
Upvotes: 0
Reputation: 399
Fast forward to 2021 and Rails 6.x, if you completely removed Webpacker and Sprockets/Asset Pipeline, replace the bin/yarn
file content with something like:
#!/usr/bin/env ruby
puts 'Yarn not present, nothing to do.'
@danielricecodes's advice is probably still valid but way more invasive.
Upvotes: 0
Reputation: 3069
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.
Upvotes: 11
Reputation: 3586
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.
Upvotes: 0
Reputation: 3297
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:
git push origin master
git push heroku master
Upvotes: 3
Reputation: 11342
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
Upvotes: 0