Skip to content

Commit 5061349

Browse files
justin808claude
andcommitted
Add enhanced development server tools from React on Rails 16
Brought over development improvements from justin-808-test-update-ror-v15: - Enhanced bin/dev script using ReactOnRails::Dev tools - Added bin/dev-static for static asset development mode - Added Procfile.dev-static-assets for webpack watching without HMR - Added Procfile.dev-prod-assets for production asset development - Updated Procfile.dev to use bin/rails instead of bundle exec These improvements provide better development workflows: - bin/dev: Default HMR development (existing) - bin/dev static: Static assets with webpack watching - Multiple Procfile options for different development modes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d292338 commit 5061349

File tree

5 files changed

+59
-49
lines changed

5 files changed

+59
-49
lines changed

Procfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# You can run these commands in separate shells
33
rescript: yarn res:dev
44
redis: redis-server
5-
rails: bundle exec rails s -p 3000
5+
rails: bin/rails s -p 3000
66
wp-client: HMR=true RAILS_ENV=development NODE_ENV=development bin/shakapacker-dev-server
77
wp-server: bundle exec rake react_on_rails:locale && HMR=true SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch

Procfile.dev-prod-assets

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# You can run these commands in separate shells
2+
web: bin/rails s -p 3001
3+
redis: redis-server
4+
5+
# Next line runs a watch process with webpack to compile the changed files.
6+
# When making frequent changes to client side assets, you will prefer building webpack assets
7+
# upon saving rather than when you refresh your browser page.
8+
# Note, if using React on Rails localization you will need to run
9+
# `bundle exec rake react_on_rails:locale` before you run bin/shakapacker
10+
webpack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'

Procfile.dev-static-assets

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# You can run these commands in separate shells
2+
web: bin/rails s -p 3000
3+
redis: redis-server
4+
5+
# Next line runs a watch process with webpack to compile the changed files.
6+
# When making frequent changes to client side assets, you will prefer building webpack assets
7+
# upon saving rather than when you refresh your browser page.
8+
# Note, if using React on Rails localization you will need to run
9+
# `bundle exec rake react_on_rails:locale` before you run bin/shakapacker
10+
webpack: sh -c 'bundle exec rake react_on_rails:locale && rm -rf public/packs/* || true && bin/shakapacker -w'

bin/dev

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
#!/usr/bin/env ruby
22
# frozen_string_literal: true
33

4-
def installed?(process)
5-
IO.popen "#{process} -v"
6-
rescue Errno::ENOENT
7-
false
8-
end
4+
# ReactOnRails Development Server
5+
#
6+
# This script provides a simple interface to the ReactOnRails development
7+
# server management. The core logic is implemented in ReactOnRails::Dev
8+
# classes for better maintainability and testing.
9+
#
10+
# Each command uses a specific Procfile for process management:
11+
# - bin/dev (default/hmr): Uses Procfile.dev
12+
# - bin/dev static: Uses Procfile.dev-static-assets-assets
13+
# - bin/dev prod: Uses Procfile.dev-prod-assets
14+
#
15+
# To customize development environment:
16+
# 1. Edit the appropriate Procfile to modify which processes run
17+
# 2. Modify this script for project-specific command-line behavior
18+
# 3. Extend ReactOnRails::Dev classes in your Rails app for advanced customization
19+
# 4. Use classes directly: ReactOnRails::Dev::ServerManager.start(:development, "Custom.procfile")
920

10-
def run(process)
11-
system "#{process} start -f Procfile.dev"
12-
rescue Errno::ENOENT
13-
warn <<~MSG
14-
ERROR:
15-
Please ensure `Procfile.dev` exists in your project!
16-
MSG
17-
exit!
21+
begin
22+
require "bundler/setup"
23+
require "react_on_rails/dev"
24+
rescue LoadError
25+
# Fallback for when gem is not yet installed
26+
puts "Loading ReactOnRails development tools..."
27+
require_relative "../../lib/react_on_rails/dev"
1828
end
1929

20-
if installed? "overmind"
21-
run "overmind"
22-
elsif installed? "foreman"
23-
run "foreman"
24-
else
25-
warn <<~MSG
26-
NOTICE:
27-
For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
28-
MSG
29-
exit!
30-
end
30+
# Main execution
31+
ReactOnRails::Dev::ServerManager.run_from_command_line(ARGV)

bin/dev-static

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
#!/usr/bin/env ruby
22
# frozen_string_literal: true
33

4-
def installed?(process)
5-
IO.popen "#{process} -v"
6-
rescue Errno::ENOENT
7-
false
8-
end
4+
# ReactOnRails Development Server - Static Assets Mode
5+
#
6+
# This runs development with static assets instead of HMR.
7+
# Useful when you want faster startup or HMR is causing issues.
98

10-
def run(process)
11-
system "#{process} start -f Procfile.dev-static"
12-
rescue Errno::ENOENT
13-
warn <<~MSG
14-
ERROR:
15-
Please ensure `Procfile.dev-static` exists in your project!
16-
MSG
17-
exit!
9+
begin
10+
require "bundler/setup"
11+
require "react_on_rails/dev"
12+
rescue LoadError
13+
# Fallback for when gem is not yet installed
14+
puts "Loading ReactOnRails development tools..."
15+
require_relative "../../lib/react_on_rails/dev"
1816
end
1917

20-
if installed? "overmind"
21-
run "overmind"
22-
elsif installed? "foreman"
23-
run "foreman"
24-
else
25-
warn <<~MSG
26-
NOTICE:
27-
For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
28-
MSG
29-
exit!
30-
end
18+
# Force static mode by passing 'static' argument
19+
ReactOnRails::Dev::ServerManager.run_from_command_line(['static'])

0 commit comments

Comments
 (0)