From e1e6b0a2b43502e96b736afef20faa7ef1f9d0e6 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Thu, 26 Oct 2023 14:30:59 +0200 Subject: [PATCH 1/4] Do not fallback compile on naos --- config/environments/staging.rb | 3 +++ 1 file changed, 3 insertions(+) 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 From f010b2a8950defac4be71db0e4cf9017a7a37f19 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Thu, 26 Oct 2023 15:00:23 +0200 Subject: [PATCH 2/4] copy nodigest assets --- config/deploy/staging.rb | 9 +++++++++ config/initializers/assets.rb | 2 +- config/webpack/webpack.config.js | 2 +- lib/tasks/assets.rake | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) 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/initializers/assets.rb b/config/initializers/assets.rb index 5536ac4aa7..eaf8a16e45 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -13,4 +13,4 @@ # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css ) -Rails.application.config.assets.nodigest = [] +Rails.application.config.assets.nodigest = ['*.nodigest.js'] 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..9fce2baa24 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -3,7 +3,7 @@ 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) + source = File.join('app/assets/builds', asset) dest = File.join(assets_path, asset) FileUtils.copy_file(source, dest) end From 21f0a5d5dd901f2e533e9c091845d69da48fa09c Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Thu, 26 Oct 2023 15:13:28 +0200 Subject: [PATCH 3/4] Fix file copy with glob --- config/initializers/assets.rb | 2 +- lib/tasks/assets.rake | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index eaf8a16e45..366581af0a 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -13,4 +13,4 @@ # folder are already added. # Rails.application.config.assets.precompile += %w( admin.js admin.css ) -Rails.application.config.assets.nodigest = ['*.nodigest.js'] +Rails.application.config.assets.nodigest = ['*.nodigest.js', '*.load_by_url'] diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 9fce2baa24..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/builds', 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 From 2090dcaa465e51aabc8fdef2cf153c71e034b40e Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Thu, 26 Oct 2023 15:26:29 +0200 Subject: [PATCH 4/4] Add comment --- config/initializers/assets.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 366581af0a..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 ) +# 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']