Skip to content

Commit 56780fd

Browse files
authored
Respect config.enable_reloading (#172)
Currently importmap-rails adds some file watchers even when `enable_reloading` is false. This PR fixes that.
1 parent c7b9e13 commit 56780fd

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Diff for: lib/importmap/engine.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ class Engine < ::Rails::Engine
2020
end
2121

2222
initializer "importmap.reloader" do |app|
23-
Importmap::Reloader.new.tap do |reloader|
24-
reloader.execute
25-
app.reloaders << reloader
26-
app.reloader.to_run { reloader.execute }
23+
unless app.config.cache_classes
24+
Importmap::Reloader.new.tap do |reloader|
25+
reloader.execute
26+
app.reloaders << reloader
27+
app.reloader.to_run { reloader.execute }
28+
end
2729
end
2830
end
2931

3032
initializer "importmap.cache_sweeper" do |app|
31-
if app.config.importmap.sweep_cache
33+
if app.config.importmap.sweep_cache && !app.config.cache_classes
3234
app.config.importmap.cache_sweepers << app.root.join("app/javascript")
3335
app.config.importmap.cache_sweepers << app.root.join("vendor/javascript")
3436
app.importmap.cache_sweeper(watches: app.config.importmap.cache_sweepers)

Diff for: lib/importmap/map.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def digest(resolver:)
6969
Digest::SHA1.hexdigest(to_json(resolver: resolver).to_s)
7070
end
7171

72-
# Returns an instance ActiveSupport::EventedFileUpdateChecker configured to clear the cache of the map
72+
# Returns an instance of ActiveSupport::EventedFileUpdateChecker configured to clear the cache of the map
7373
# when the directories passed on initialization via `watches:` have changes. This is used in development
7474
# and test to ensure the map caches are reset when javascript files are changed.
7575
def cache_sweeper(watches: nil)

0 commit comments

Comments
 (0)