Skip to content

Commit

Permalink
Setup importmap (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
damianlegawiec committed Mar 10, 2024
1 parent 964304f commit 6f6a77e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app/assets/config/spree_frontend_manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//= link_directory ../../javascript/spree/frontend .js

//= link_tree ../images
//
//= link spree/frontend/all.js
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/spree/frontend/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
2 changes: 1 addition & 1 deletion app/views/spree/shared/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<%= stylesheet_link_tag 'spree/frontend/all', media: 'screen', data: { turbo_track: 'reload' } %>
<%= csrf_meta_tags %>
<%= javascript_importmap_tags %>
<%= javascript_importmap_tags('application-spree-frontend') %>
<%= render 'spree/shared/paths' %>
<%= render 'spree/shared/locale_and_currency' %>
<%= javascript_include_tag 'spree/frontend/all', defer: true, data: { turbo_track: 'reload' } %>
Expand Down
2 changes: 2 additions & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pin "application-spree-frontend", to: "spree/frontend/application.js", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
14 changes: 9 additions & 5 deletions lib/spree/frontend/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ class Engine < ::Rails::Engine
config.action_view.sanitized_allowed_tags = %w(a b del em i ins mark p small strong sub sup)
config.action_view.sanitized_allowed_attributes = %w(href)

# sets the manifests / assets to be precompiled, even when initialize_on_precompile is false
initializer 'spree.assets.precompile', group: :all do |app|
app.config.assets.precompile += %w[
spree/frontend/all*
]
initializer "spree.frontend.assets" do |app|
app.config.assets.paths << root.join("app/javascript")
app.config.assets.precompile += %w[ spree_frontend_manifest ]
end

initializer 'spree.frontend.importmap', before: 'importmap' do |app|
app.config.importmap.paths << root.join('config/importmap.rb')
# https://github.com/rails/importmap-rails?tab=readme-ov-file#sweeping-the-cache-in-development-and-test
app.config.importmap.cache_sweepers << root.join('app/javascript')
end

initializer 'spree.frontend.environment', before: :load_config_initializers do |_app|
Expand Down
2 changes: 1 addition & 1 deletion spree_frontend.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_frontend'
s.version = Spree::Frontend.version
s.authors = ['Sean Schofield', 'Spark Solutions', 'Vendo Inc.']
s.authors = ['Sean Schofield', 'Spark Solutions', 'Vendo Connect Inc.']
s.email = 'hello@spreecommerce.org'
s.summary = 'The default Storefront built with Rails and Turbo/Hotwire for Spree eCommerce platform'
s.description = s.summary
Expand Down

0 comments on commit 6f6a77e

Please sign in to comment.