Home > Enterprise >  How to not require "rails/all"?
How to not require "rails/all"?

Time:01-06

> CUT_OFF=10 bundle exec derailed bundle:mem
TOP: 129.6563 MiB
  rails/all: 58.1406 MiB
    action_mailbox/engine: 32.1719 MiB

I would like to not require action_mailbox/engine but it's required by rails/all

I'm not sure which gem it is.

I tried:

def require(file)
  puts "#{file} => #{caller.first}"
  super
end

But nothing shows up

CodePudding user response:

It was weird that just by looking at Gemfile rails/all somehow was getting loaded. Sometimes just searching helps:

$ ag "rails/all" `bundle show --paths`
/home/alex/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/derailed_benchmarks-2.1.2/bin/derailed
90:          require 'rails/all'

# ... 2 more results from `.tt` files

To answer your question, you can split rails gem and use what you need. I've answered that before:
https://stackoverflow.com/a/71993557/207090

Now in config/application.rb you can replace:

require "rails/all"

with requires in all.rb from railties gem and remove what you don't need:
https://github.com/rails/rails/blob/v7.0.4/railties/lib/rails/all.rb

you don't really have to, since missing files get rescued and app will boot with no issues. Any references/configs for mailbox have to be removed.

# config/application.rb

# require "rails/all"
require "rails"
%w(
  active_record/railtie
  active_storage/engine
  action_controller/railtie
  action_view/railtie
  active_job/railtie
  action_cable/engine
  action_text/engine
  rails/test_unit/railtie
).each do |railtie|
  # action_mailer/railtie
  # action_mailbox/engine
  begin
    require railtie
  rescue LoadError
  end
end       
  • Related