Skip to content

Commit a8955fe

Browse files
committed
Add an option to ignore unnecessary directories such as node_modules/
The `Listen.to` method accepts an `ignore` option, allowing the listener to ignore paths matching specified patterns. In this commit, the `ignore` option passed to the Listen.to method is made configurable through a configuration file.
1 parent e173832 commit a8955fe

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/generators/templates/rails_live_reload.rb

+3
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
# config.watch %r{app/helpers/.+\.rb}, reload: :always
1212
# config.watch %r{config/locales/.+\.yml}, reload: :always
1313

14+
# Ignored folders & files
15+
# config.ignore %r{node_modules/}
16+
1417
# config.enabled = Rails.env.development?
1518
end if defined?(RailsLiveReload)

lib/rails_live_reload/config.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ def patterns
1212
config.patterns
1313
end
1414

15+
def ignore_patterns
16+
config.ignore_patterns
17+
end
18+
1519
def enabled?
1620
config.enabled
1721
end
1822
end
1923

2024
class Config
21-
attr_reader :patterns
25+
attr_reader :patterns, :ignore_patterns
2226
attr_accessor :url, :watcher, :files, :enabled
2327

2428
def initialize
@@ -33,6 +37,8 @@ def initialize
3337
%r{(app|vendor)/(assets|javascript)/\w+/(.+\.(css|js|html|png|jpg|ts|jsx)).*} => :always
3438
}
3539
@default_patterns_changed = false
40+
41+
@ignore_patterns = []
3642
end
3743

3844
def root_path
@@ -48,6 +54,10 @@ def watch(pattern, reload: :on_change)
4854
patterns[pattern] = reload
4955
end
5056

57+
def ignore(pattern)
58+
@ignore_patterns << pattern
59+
end
60+
5161
def socket_path
5262
root_path.join('tmp/sockets/rails_live_reload.sock').then do |path|
5363
break path if path.to_s.size <= 104 # 104 is the max length of a socket path

lib/rails_live_reload/watcher.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def initialize
2727

2828
def start_listener
2929
Thread.new do
30-
listener = Listen.to(root) do |modified, added, removed|
30+
listener = Listen.to(root, ignore: RailsLiveReload.ignore_patterns) do |modified, added, removed|
3131
all = modified + added + removed
3232
all.each do |file|
3333
files[file] = File.mtime(file).to_i rescue nil

0 commit comments

Comments
 (0)