diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index 5fe7d152d4..08d57ba2b2 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -22,4 +22,13 @@ end end end + before :publishing, :asset_stuff do + on roles :web do + within release_path do + with rails_env: fetch(:rails_env) do + execute :rake, 'assets:nodigest' + end + end + end + end end diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 643aee253e..6aeff0c4d6 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -64,6 +64,9 @@ # Compress JavaScripts and CSS. config.assets.js_compressor = :terser + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + # Asset digests allow you to set far-future HTTP expiration dates on all assets, # yet still be able to expire them through the digest params. config.assets.digest = true diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 5536ac4aa7..6544844273 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -13,4 +13,7 @@ # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css ) -Rails.application.config.assets.nodigest = [] +# These files are fetched from within other js assets +# so they do not support rails sprockets renaming them +# We need to provide them as assets without digest +Rails.application.config.assets.nodigest = ['*.nodigest.js', '*.load_by_url'] diff --git a/config/webpack/webpack.config.js b/config/webpack/webpack.config.js index 87babe92e3..29418f9e78 100644 --- a/config/webpack/webpack.config.js +++ b/config/webpack/webpack.config.js @@ -42,7 +42,7 @@ const config = { filename: "[name].js", sourceMapFilename: "[name].js.map", path: path.resolve(__dirname, "..", "..", "app/assets/builds"), - chunkFilename: "[name].[chunkhash].js", + chunkFilename: "[name].[chunkhash].nodigest.js", }, resolve: { modules: ["node_modules", "app/assets/javascripts"], diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index e48d912337..4eb0acb8d8 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -3,9 +3,11 @@ namespace :assets do task nodigest: :environment do assets_path = File.join(Rails.root, 'public', Rails.configuration.assets.prefix) Rails.configuration.assets.nodigest.each do |asset| - source = File.join('app/assets/javascripts', asset) - dest = File.join(assets_path, asset) - FileUtils.copy_file(source, dest) + Dir.glob(File.join('app/assets/builds', asset)).each do |source_path| + file_name = File.basename(source_path) + dest_path = File.join(assets_path, file_name) + FileUtils.copy_file(source_path, dest_path) + end end end end