Skip to content

Commit e410de6

Browse files
justin808claude
andcommitted
Simplify build orchestration for rescript and locale generation
- bin/dev now runs rescript build and locale generation BEFORE starting Procfile processes, eliminating race conditions and sleep delays - Added res:watch npm script (watch without clean) for Procfile.dev - Removed sleep delays and inline locale generation from Procfile.dev - Updated build_production_command to include rescript build - Removed precompile_hook from shakapacker.yml (handled by bin/dev and build commands) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent a332db4 commit e410de6

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

Procfile.dev

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Procfile for development using HMR
22
# You can run these commands in separate shells
3-
# ReScript: clean and rebuild, then watch for changes
4-
rescript: yarn res:dev
3+
#
4+
# Note: bin/dev runs precompile tasks (rescript + locale) BEFORE starting these processes.
5+
# This ensures all generated files exist before webpack starts watching.
6+
#
7+
# ReScript watch mode (no clean - bin/dev already did the clean build)
8+
rescript: yarn res:watch
59
# redis: redis-server # Run Redis as a system service instead (brew services start redis)
610
rails: bundle exec thrust bin/rails server -p 3000
7-
# Sleep to allow rescript files to compile before starting webpack
8-
# Increased sleep time to ensure rescript initial build completes
9-
wp-client: sleep 15 && RAILS_ENV=development NODE_ENV=development bin/shakapacker-dev-server
10-
wp-server: sleep 15 && bundle exec rake react_on_rails:locale && HMR=true SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch
11+
# Client webpack dev server with HMR
12+
wp-client: RAILS_ENV=development NODE_ENV=development bin/shakapacker-dev-server
13+
# Server webpack watcher for SSR bundle
14+
wp-server: HMR=true SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch

config/initializers/react_on_rails.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
config.components_subdirectory = "ror_components"
77
config.auto_load_bundle = true
88

9-
# Build commands with locale generation
10-
config.build_test_command = "RAILS_ENV=test bin/shakapacker"
11-
config.build_production_command =
12-
"bundle exec rake react_on_rails:locale && RAILS_ENV=production NODE_ENV=production bin/shakapacker"
9+
# Build commands
10+
# Note: react_on_rails:assets:webpack (run by assets:precompile) depends on react_on_rails:locale,
11+
# so locale generation happens automatically. We just need rescript to run first.
12+
config.build_test_command = "yarn res:build && RAILS_ENV=test bin/shakapacker"
13+
config.build_production_command = "yarn res:build && RAILS_ENV=production NODE_ENV=production bin/shakapacker"
1314

1415
# This is the file used for server rendering of React when using `(prerender: true)`
1516
# If you are never using server rendering, you may set this to "".

config/shakapacker.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ default: &default
2121
# Use the config.build_production_command in config/initializers/react_on_rails.rb
2222
shakapacker_precompile: false
2323

24+
# Note: precompile_hook is not used here because:
25+
# - In development: bin/dev runs rescript + locale before starting processes
26+
# - In production: build_production_command includes rescript, and
27+
# react_on_rails:assets:webpack already depends on react_on_rails:locale
28+
2429
development:
2530
<<: *default
2631
# This is false since we're running `bin/shakapacker -w` in Procfile.dev-setic

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"res:clean": "rescript clean",
2222
"res:format": "rescript format -all",
2323
"res:dev": "yarn res:clean && rescript build -w",
24+
"res:watch": "rescript build -w",
2425
"res:build": "yarn res:clean && rescript build",
2526
"lint:eslint": "yarn eslint client --ext \".js,.jsx,.ts\"",
2627
"lint:prettier": "yarn prettier \"**/*.@(js|jsx)\" --list-different",

0 commit comments

Comments
 (0)