From 039bb3fc368689d81cec5b530c3bacb689345021 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Mon, 12 Feb 2024 08:44:22 +0200 Subject: [PATCH] fix(js): allow pinning importmaps with gem 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