Skip to content

Commit

Permalink
Allow app to opt out of precompiling activestorage js assets (#43967)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlestavel committed Jan 18, 2022
1 parent 32a82eb commit 2197814
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions actioncable/lib/action_cable/engine.rb
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions activestorage/lib/active_storage/engine.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions guides/source/configuring.md
Expand Up @@ -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:
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit 2197814

Please sign in to comment.