Anybody here good with invoking background processes in Ruby?
It’s too easy to start rails using
rails s and not have the JS code update. It should be fine just run
rails s in development mode. We also need to make sure that the js code is updated before rspec starts. Thus, we should have the Rails server invoke webpack, so that it’s impossible to forget to start webpack to do this background compilation.
In essence, we need to fork webpack watch processes to compile the bundle JS files when needed.
Basically, this means taking what’s in the forman file:
server: sh -c 'cd client && $(npm bin)/webpack -w --config webpack.server.js' client: sh -c 'cd client && $(npm bin)/webpack -w --config webpack.client.js' web: bin/rails s
And having this simply work by running
The requirements would be:
- All stdout and stderr from the webpack commands goes to stdout for the rails server.
- The webpack processes quit when the rails server quits, and preferably even if the the rails server is killed with a
This article on StackOverflow suggests we should use Ruby “fork”