|
| 1 | +# Using Process Managers with React on Rails |
| 2 | + |
| 3 | +React on Rails requires running multiple processes simultaneously during development: |
| 4 | + |
| 5 | +- Rails server |
| 6 | +- Webpack dev server (client bundle) |
| 7 | +- Webpack watcher (server bundle) |
| 8 | + |
| 9 | +## Running Your Development Server |
| 10 | + |
| 11 | +React on Rails includes `bin/dev` which automatically uses Overmind or Foreman: |
| 12 | + |
| 13 | +```bash |
| 14 | +./bin/dev |
| 15 | +``` |
| 16 | + |
| 17 | +This script will: |
| 18 | + |
| 19 | +1. Try to use Overmind (if installed) |
| 20 | +2. Fall back to Foreman (if installed) |
| 21 | +3. Show installation instructions if neither is found |
| 22 | + |
| 23 | +## Installing a Process Manager |
| 24 | + |
| 25 | +### Overmind (Recommended) |
| 26 | + |
| 27 | +Overmind provides easier debugging and better signal handling: |
| 28 | + |
| 29 | +```bash |
| 30 | +# macOS |
| 31 | +brew install overmind |
| 32 | + |
| 33 | +# Linux |
| 34 | +# See: https://github.com/DarthSim/overmind#installation |
| 35 | +``` |
| 36 | + |
| 37 | +### Foreman (Alternative) |
| 38 | + |
| 39 | +Foreman is a widely-used Ruby-based process manager: |
| 40 | + |
| 41 | +```bash |
| 42 | +# Install globally (NOT in Gemfile) |
| 43 | +gem install foreman |
| 44 | +``` |
| 45 | + |
| 46 | +**Important:** Do NOT add Foreman to your `Gemfile`. Install it globally on your system. |
| 47 | + |
| 48 | +**Why not in Gemfile?** |
| 49 | + |
| 50 | +From [Foreman's documentation](https://github.com/ddollar/foreman/wiki/Don't-Bundle-Foreman): |
| 51 | + |
| 52 | +> Foreman is not a library, and should not affect the dependency tree of your application. |
| 53 | +
|
| 54 | +Key reasons: |
| 55 | + |
| 56 | +- **Dependency conflicts**: Including Foreman in your Gemfile can create dependency conflicts that break other projects |
| 57 | +- **Security risk**: Loading Foreman as an application dependency creates an unnecessary security vulnerability vector |
| 58 | +- **Stability**: Foreman is mature and stable; bundling it could introduce bugs from unnecessary dependency updates |
| 59 | +- **Wrong abstraction**: Foreman is a system tool, not an application dependency |
| 60 | + |
| 61 | +Install Foreman globally: `gem install foreman` |
| 62 | + |
| 63 | +## Alternative: Run Process Managers Directly |
| 64 | + |
| 65 | +You can also run process managers directly instead of using `bin/dev`: |
| 66 | + |
| 67 | +```bash |
| 68 | +# With Overmind |
| 69 | +overmind start -f Procfile.dev |
| 70 | + |
| 71 | +# With Foreman |
| 72 | +foreman start -f Procfile.dev |
| 73 | +``` |
| 74 | + |
| 75 | +## Customizing Your Setup |
| 76 | + |
| 77 | +Edit `Procfile.dev` in your project root to customize which processes run and their configuration. |
| 78 | + |
| 79 | +The default `Procfile.dev` includes: |
| 80 | + |
| 81 | +```procfile |
| 82 | +rails: bundle exec rails s -p 3000 |
| 83 | +wp-client: bin/shakapacker-dev-server |
| 84 | +wp-server: SERVER_BUNDLE_ONLY=true bin/shakapacker --watch |
| 85 | +``` |
| 86 | + |
| 87 | +## See Also |
| 88 | + |
| 89 | +- [HMR and Hot Reloading](./hmr-and-hot-reloading-with-the-webpack-dev-server.md) |
| 90 | +- [Foreman documentation](https://github.com/ddollar/foreman) |
| 91 | +- [Overmind documentation](https://github.com/DarthSim/overmind) |
0 commit comments