From 7bd0aef5c8199cec3d9e1935331531f8e28cbcf1 Mon Sep 17 00:00:00 2001 From: Daniel Jackson Date: Sun, 28 Jan 2024 13:36:19 +0100 Subject: [PATCH] Cache precompiled inline svgs, so they work with assets.compile = false in prod --- config/initializers/inilne_svg_cache.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 config/initializers/inilne_svg_cache.rb diff --git a/config/initializers/inilne_svg_cache.rb b/config/initializers/inilne_svg_cache.rb new file mode 100644 index 00000000..1bc4dc46 --- /dev/null +++ b/config/initializers/inilne_svg_cache.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# This caches all SVGs in assets folder, and solves inline svg for +# production use. + +InlineSvg.configure do |config| + # Only precompile if we aren't compiling on the fly + return if Rails.application.config.assets.compile + + assets_path = Rails.public_path.join("assets").to_s + return unless Dir.exist? assets_path + + config.asset_file = InlineSvg::CachedAssetFile.new( + paths: [ + assets_path + ], + filters: /\.svg/ + ) +end