Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assets not available in production #5082

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/deploy/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
2 changes: 1 addition & 1 deletion config/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
8 changes: 5 additions & 3 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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