From 1a46c4a1ec82f3b197b33d35ec4e8c68eba5f1d7 Mon Sep 17 00:00:00 2001 From: Julien Lestavel Date: Tue, 28 Dec 2021 18:00:53 +0100 Subject: [PATCH] Allow app to opt out of precompiling activestorage js assets --- actioncable/lib/action_cable/engine.rb | 4 ++-- activestorage/lib/active_storage/engine.rb | 7 +++++-- guides/source/configuring.md | 10 ++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/actioncable/lib/action_cable/engine.rb b/actioncable/lib/action_cable/engine.rb index 9d95b28d22c42..e369068ade833 100644 --- a/actioncable/lib/action_cable/engine.rb +++ b/actioncable/lib/action_cable/engine.rb @@ -25,8 +25,8 @@ class Engine < Rails::Engine # :nodoc: initializer "action_cable.asset" do config.after_initialize do |app| - if Rails.application.config.respond_to?(:assets) && app.config.action_cable.precompile_assets - Rails.application.config.assets.precompile += %w( actioncable.js actioncable.esm.js ) + if app.config.respond_to?(:assets) && app.config.action_cable.precompile_assets + app.config.assets.precompile += %w( actioncable.js actioncable.esm.js ) end end end diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb index 81306ff3baee1..53495011ab600 100644 --- a/activestorage/lib/active_storage/engine.rb +++ b/activestorage/lib/active_storage/engine.rb @@ -30,6 +30,7 @@ class Engine < Rails::Engine # :nodoc: config.active_storage.analyzers = [ ActiveStorage::Analyzer::ImageAnalyzer::Vips, ActiveStorage::Analyzer::ImageAnalyzer::ImageMagick, ActiveStorage::Analyzer::VideoAnalyzer, ActiveStorage::Analyzer::AudioAnalyzer ] config.active_storage.paths = ActiveSupport::OrderedOptions.new config.active_storage.queues = ActiveSupport::InheritableOptions.new + config.active_storage.precompile_assets = true config.active_storage.variable_content_types = %w( image/png @@ -167,8 +168,10 @@ class Engine < Rails::Engine # :nodoc: end initializer "active_storage.asset" do - if Rails.application.config.respond_to?(:assets) - Rails.application.config.assets.precompile += %w( activestorage activestorage.esm ) + config.after_initialize do |app| + if app.config.respond_to?(:assets) && app.config.active_storage.precompile_assets + app.config.assets.precompile += %w( activestorage activestorage.esm ) + end end end diff --git a/guides/source/configuring.md b/guides/source/configuring.md index afe9c212939bc..59d2bb06f2115 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -1972,6 +1972,11 @@ Cable as part of your normal Rails server. You can find more detailed configuration options in the [Action Cable Overview](action_cable_overview.html#configuration). +#### `config.action_cable.precompile_assets` + +Determines whether the Action Cable assets should be added to the asset pipeline precompilation. It +has no effect if Sprockets is not used. The default value is `true`. + ### Configuring Active Storage `config.active_storage` provides the following configuration options: @@ -2192,6 +2197,11 @@ The default value depends on the `config.load_defaults` target version: | (original) | `false` | | 7.0 | `true` | +#### `config.active_storage.precompile_assets` + +Determines whether the Active Storage assets should be added to the asset pipeline precompilation. It +has no effect if Sprockets is not used. The default value is `true`. + ### Configuring Action Text #### `config.action_text.attachment_tag_name`