DeadweightRails
DeadweightRails scans your Rails project for unused assets and Ruby code, helping you reduce bundle size, improve performance, and clean your codebase.
Features
- Detect unused CSS and JS in Rails asset pipeline
- Detect unused Ruby methods
- Generate a report in terminal with colored output
- Works with standard Rails directories (
app/assets,app/views,app/models) - Simple Rake task integration
Installation
Add this line to your Gemfile:
gem 'deadweight_rails'Then execute:
bundle installOr install it yourself:
gem install deadweight_railsUsage
1. Rake task
Add this task to lib/tasks/deadweight.rake:
require "rake"
require "deadweight_rails"
namespace :deadweight do
desc "Scan Rails project for unused assets and Ruby code"
task :scan do
DeadweightRails.run
end
endRun the task:
bundle exec rake deadweight:scan2. Programmatically
require "deadweight_rails"
# Scan current Rails project
DeadweightRails.run
# Or scan a specific path
DeadweightRails.run(path: "/path/to/project")Example Output
🔎 DEADWEIGHTRAILS REPORT
--- Assets ---
Unused CSS: old.css
Unused JS: legacy.js
--- Ruby ---
Unused Methods: old_helper
Development
After checking out the repo, run:
bin/setup
rake spec
bin/consoleTo install the gem locally:
bundle exec rake installTo release a new version:
bundle exec rake releaseContributing
Bug reports and pull requests are welcome on GitHub: gem "deadweight_rails", path: "../deadweight_rails" https://github.com/[USERNAME]/deadwe