Skip to content

Commit a2bfc08

Browse files
justin808claude
andcommitted
Add ReScript build step before starting development server
When bin/dev starts, webpack immediately tries to build bundles that import ReScript components (HelloWorldReScript.res.js). However, these .res.js files are generated by the ReScript compiler from .res source files, and webpack fails if they don't exist yet. Solution: Build ReScript files before starting the Procfile processes. This ensures all .res.js files are generated before webpack starts. Changes: - lib/react_on_rails/dev/server_manager.rb: - Add build_rescript_if_needed method to compile ReScript before dev server - Check for both bsconfig.json (old) and rescript.json (new) config files - Run yarn build:rescript if ReScript is configured - Exit with error if ReScript build fails Fixes webpack Module not found errors for HelloWorldReScript.res.js 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3b9ad52 commit a2bfc08

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/react_on_rails/dev/server_manager.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,18 +416,34 @@ def run_static_development(procfile, verbose: false, route: nil)
416416
route: route
417417
)
418418

419+
build_rescript_if_needed
419420
PackGenerator.generate(verbose: verbose)
420421
ProcessManager.ensure_procfile(procfile)
421422
ProcessManager.run_with_process_manager(procfile)
422423
end
423424

424425
def run_development(procfile, verbose: false, route: nil)
425426
print_procfile_info(procfile, route: route)
427+
build_rescript_if_needed
426428
PackGenerator.generate(verbose: verbose)
427429
ProcessManager.ensure_procfile(procfile)
428430
ProcessManager.run_with_process_manager(procfile)
429431
end
430432

433+
def build_rescript_if_needed
434+
# Check for both old (bsconfig.json) and new (rescript.json) config files
435+
return unless File.exist?("bsconfig.json") || File.exist?("rescript.json")
436+
437+
print "🔧 Building ReScript... "
438+
success = system("yarn build:rescript > /dev/null 2>&1")
439+
puts success ? "✅" : "❌"
440+
441+
return if success
442+
443+
puts "❌ ReScript build failed"
444+
exit 1
445+
end
446+
431447
def print_server_info(title, features, port = 3000, route: nil)
432448
puts title
433449
features.each { |feature| puts " - #{feature}" }

0 commit comments

Comments
 (0)