Open GCorbel opened 5 months ago
It happens before even the application is loaded, so we can't implement any logic that depends on what happened in the application. Unfortunately there is no way to do this. We could have a Watcher#remove
method so you could configure srping to stop watching a file.
I agree with Watcher#remove
.
I tried to do Spring.watcher.files.reject! { |k, v| $LOADED_FEATURES.include?(k) }
but it's not enough because spring is running in a different thread. I'm not sure how to do.
I gave a closer look and I don't see how to change files watched once the server is running.
The best solution I found ATM is adding this in config/spring.rb
:
module OverrideWatcher
def add(*items)
items.reject! { |k, _v| $LOADED_FEATURES.include?(k) }
super
end
end
Spring.watcher.extend(OverrideWatcher)
During the initialization of a Rails app, some files are required and added to
$LOADED_FEATURES
so, when they are changed, the whole app reloads.I want to avoid that and I this commenting the line that add them to the watcher fix my issue.
Is there a proper way to do that ? I don't understand at which step
Spring::Application#preload
is called but maybe it's a good idea to watch only files loaded beforeRails.application.config.after_initialize
orRails.application.config.to_preload
.