Skip to content

Commit 4c1eae2

Browse files
committed
Setup importmap
1 parent 790177c commit 4c1eae2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

app/views/layouts/spotlight/base.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
<% else %>
1414
<%= stylesheet_link_tag "application" %>
1515
<% end %>
16-
<%= javascript_include_tag "application" %>
16+
<% if defined? Importmap %>
17+
<%= javascript_importmap_tags %>
18+
<% else %>
19+
<%= javascript_include_tag "application" %>
20+
<% end %>
1721
<%= csrf_meta_tags %>
1822
<%= content_for(:head) %>
1923
<%= description %>

lib/generators/spotlight/install_generator.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ def add_js_rails6
1919
end
2020

2121
def add_manifest
22-
# Blacklight 8 does not use this directory by default.
23-
return unless File.exist?('app/assets/javascripts')
24-
25-
append_to_file 'app/assets/javascripts/application.js', "\n//= require_tree .\n"
2622
append_to_file 'app/assets/config/manifest.js', "\n//= link spotlight/manifest.js"
27-
# Rails installed importmap by default, but we don't have importmap + Blacklight 7 working yet.
28-
remove_file 'app/javascript/application.js'
23+
24+
# Blacklight 8 does not use this directory by default.
25+
if File.exist?('app/assets/javascripts')
26+
append_to_file 'app/assets/javascripts/application.js', "\n//= require_tree .\n"
27+
# Rails installed importmap by default, but we don't have importmap + Blacklight 7 working yet.
28+
remove_file 'app/javascript/application.js'
29+
else
30+
# install via importmap
31+
append_to_file 'app/javascript/application.js' do
32+
<<~CONTENT
33+
import Spotlight from "spotlight.esm"
34+
CONTENT
35+
end
36+
end
2937
end
3038

3139
def inject_spotlight_routes

0 commit comments

Comments
 (0)