Skip to content

Instantly share code, notes, and snippets.

@zealot128
Last active June 14, 2021 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zealot128/ff821bb338cf7bf5aa54b73eb18cafc2 to your computer and use it in GitHub Desktop.
Save zealot128/ff821bb338cf7bf5aa54b73eb18cafc2 to your computer and use it in GitHub Desktop.
Migrate off rails-assets.org

Migrate Gem-assets by vendoring

inspired: https://www.ramblingcode.dev/posts/bye_rails_assets/

This script + initializer can help you to migrate of the "rails-assets.org" hosted assets. If you can not immediately move to Webpack/NPM, you can just copy the asset content into your vendor directory.

Add to your config/initializers/assets.rb:

Rails.application.configure do
  config.assets.paths += Dir["#{Rails.root}/vendor/assets/rails-assets/*/*"]
end
#!/usr/bin/env ruby
require 'pry'
gems = `bundle list --paths | grep rails-assets`
gems.strip.split.each do |gem_path|
base_path = Dir[gem_path + "/*.gemspec"].first.split('/').last.sub('.gemspec', '')
target = "vendor/assets/rails-assets/#{base_path}"
FileUtils.mkdir_p(target)
puts "copying #{gem_path} -> #{target}"
Dir[gem_path + "/app/assets/*"].each do |source|
FileUtils.cp_r(source, target)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment