sprockets-rails
sprockets-rails copied to clipboard
Cannot override default app.config.assets.precompile filters
The default precompile filters are appended after the application is loaded so the filters added here (https://github.com/rails/sprockets-rails/blob/e135984ee2b07e1a67c3fa57f799f40b0830e99a/lib/sprockets/railtie.rb#L108) will always be applied regardless of what is specified in the configuration of the Rails application. Ex. Given the following assets:
- app/assets/javascripts
- dashboard.js
- dashboard.ts
If I only want dashboard.js to be precompiled and not dashboard.ts I would expect that configuring the following would do that since it is setting the configuration not appending to it:
# config/application.rb
#
# DOES NOT WORK
config.assets.precompile = ["dashboard.js"]
However, dashboard.ts will still be compiled since it matches the default rule that precompiles all files that do not end with .js or .css. This can be worked around by using an after_initialize hook, but it seems rather unintuitive.
# config/application.rb
#
# WORKS!
config.after_initialize do
config.assets.precompile = ["dashboard.js"]
end
I think this might be somewhat related to https://github.com/rails/sprockets-rails/issues/372 since it is the same offending line of code. The issue was encountered in version 3.2.0. I have another application running an older version (2.3.3) that uses the first configuration method and it works fine. Thanks!