From 1dfffc8a6d1665e7ec12428afef8ed66071e34e8 Mon Sep 17 00:00:00 2001 From: Mikael Henriksson Date: Thu, 15 Feb 2024 22:18:01 +0200 Subject: [PATCH] fix(js): allow pinning importmaps with gem (#49) Since import maps JSPM and the javascript ecosystem are a mess in their current state, allow import maps to match the assets served by the gem rather than download them from JSPM. --- lib/turbo_boost/elements/engine.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/turbo_boost/elements/engine.rb b/lib/turbo_boost/elements/engine.rb index 6a5b9a0..4985081 100644 --- a/lib/turbo_boost/elements/engine.rb +++ b/lib/turbo_boost/elements/engine.rb @@ -11,11 +11,19 @@ def self.config class Engine < ::Rails::Engine isolate_namespace TurboBoost::Elements + config.turbo_boost_elements = ActiveSupport::OrderedOptions.new + config.turbo_boost_elements.precompile_assets = true ActiveSupport.on_load(:action_controller_base) do # `self` is ActionController::Base helper TurboBoost::Elements::ApplicationHelper end + + config.after_initialize do |app| + if app.config.respond_to?(:assets) && app.config.turbo_boost_elements.precompile_assets + app.config.assets.precompile += %w[@turbo-boost/elements.js] + end + end end end