I wish to precompile all the CSS and JS files in my project\'s app/assets folder. I do NOT want to precompile everything in vendor/assets or lib/assets, only th
I'm revisiting this post at the year 2017.
Our product is still heavily using RoR, we've been continuously modifying our precompile configurations by appending Rails.application.config.assets.precompile as we're adding new modules. Recently I was trying to optimize this by adding a regex pattern, I found that the following glob pattern works:
Rails.application.config.assets.precompile += %w(**/bundle/*.js)
However I still need to exclude certain modules, so I tried hard to use regex instead of glob.
Until I looked into sprockets source code: https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb#L108 , I found that they're already using regex:
app.config.assets.precompile +=
[LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
So I change my code into:
Rails.application.config.assets.precompile +=
[/^((?!my_excluded_module)\w)*\/bundle\/\w*\.js$/]
Which works well.