Skip to content

Commit 81c66fa

Browse files
committed
Now automatically creates packs
1 parent 6562e1b commit 81c66fa

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

bin/dev

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@ rescue Errno::ENOENT
77
false
88
end
99

10+
def generate_packs
11+
puts "📦 Generating React on Rails packs..."
12+
system "bundle exec rake react_on_rails:generate_packs"
13+
14+
unless $?.success?
15+
puts "❌ Pack generation failed"
16+
exit 1
17+
end
18+
end
19+
1020
def run_production_like
1121
puts "🏭 Starting production-like development server..."
22+
puts " - Generating React on Rails packs"
1223
puts " - Precompiling assets with production optimizations"
1324
puts " - Running Rails server on port 3001"
1425
puts " - No HMR (Hot Module Replacement)"
@@ -17,7 +28,11 @@ def run_production_like
1728
puts "💡 Access at: http://localhost:3001"
1829
puts ""
1930

31+
# Generate React on Rails packs first
32+
generate_packs
33+
2034
# Precompile assets in production mode
35+
puts "🔨 Precompiling assets..."
2136
system "RAILS_ENV=production NODE_ENV=production bundle exec rails assets:precompile"
2237

2338
if $?.success?
@@ -38,6 +53,7 @@ end
3853

3954
def run_static_development
4055
puts "⚡ Starting development server with static assets..."
56+
puts " - Generating React on Rails packs"
4157
puts " - Using shakapacker --watch (no HMR)"
4258
puts " - CSS extracted to separate files (no FOUC)"
4359
puts " - Development environment (source maps, faster builds)"
@@ -46,6 +62,9 @@ def run_static_development
4662
puts "💡 Access at: http://localhost:3000"
4763
puts ""
4864

65+
# Generate React on Rails packs first
66+
generate_packs
67+
4968
if installed? "overmind"
5069
system "overmind start -f Procfile.dev-static"
5170
elsif installed? "foreman"
@@ -66,6 +85,8 @@ rescue Errno::ENOENT
6685
end
6786

6887
def run_development(process)
88+
generate_packs
89+
6990
system "#{process} start -f Procfile.dev"
7091
rescue Errno::ENOENT
7192
warn <<~MSG
@@ -85,41 +106,38 @@ elsif ARGV[0] == "help" || ARGV[0] == "--help" || ARGV[0] == "-h"
85106
Usage: bin/dev [command]
86107
87108
Commands:
88-
(none) Start development server with HMR (default)
109+
(none) / hmr Start development server with HMR (default)
89110
static Start development server with static assets (no HMR, no FOUC)
90111
production-assets Start with production-optimized assets (no HMR)
91112
prod Alias for production-assets
92113
help Show this help message
93114
94-
Development mode (default):
115+
HMR Development mode (default):
95116
• Hot Module Replacement (HMR) enabled
117+
• Automatic React on Rails pack generation
96118
• Source maps for debugging
97119
• May have Flash of Unstyled Content (FOUC)
98120
• Fast recompilation
99121
• Access at: http://localhost:3000
100122
101123
Static development mode:
102124
• No HMR (static assets with auto-recompilation)
125+
• Automatic React on Rails pack generation
103126
• CSS extracted to separate files (no FOUC)
104127
• Development environment (faster builds than production)
105128
• Source maps for debugging
106129
• Access at: http://localhost:3000
107130
108131
Production-assets mode:
132+
• Automatic React on Rails pack generation
109133
• Optimized, minified bundles
110134
• Extracted CSS files (no FOUC)
111135
• No HMR (static assets)
112136
• Slower recompilation
113137
• Access at: http://localhost:3001
114138
HELP
115-
else
116-
# Default development mode
117-
if ARGV[0]
118-
puts "Unknown argument: #{ARGV[0]}"
119-
puts "Run 'bin/dev help' for usage information"
120-
exit 1
121-
end
122-
139+
elsif ARGV[0] == "hmr" || ARGV[0].nil?
140+
# Default development mode (HMR)
123141
if installed? "overmind"
124142
run_development "overmind"
125143
elsif installed? "foreman"
@@ -131,4 +149,9 @@ else
131149
MSG
132150
exit!
133151
end
152+
else
153+
# Unknown argument
154+
puts "Unknown argument: #{ARGV[0]}"
155+
puts "Run 'bin/dev help' for usage information"
156+
exit 1
134157
end

0 commit comments

Comments
 (0)