Webpack Hot Reload And Rails03 May 2015
Webpack seems to be getting plenty of lip service these days. Doubly so in the React community which means most of Facebook. Since Rails leans so heavily on the asset pipeline, how can we merge ES6, modules, and other bits of Webpack greatness with the age old, do one thing well: Sprockets
The following two scripts (one used for Development, the other Production), show that Webpack can easily integrate with Rail’s existing asset pipeline. While giving way to utilizing many of the best features hidden in Webpack.
A few caveats about running these scripts:
- The directory structure assumes a
./clientfolder, top level in your Rails app.
- The common/development script assumes that assets will be served from a server.
This means you will need a few
- The two urls for this server are: http://localhost:8080/webpack-dev-server.js and http://localhost:8080/bundle.js.
- To run the Dev script:
$(npm bin)/webpack-dev-server --config webpack.config.js --hot --progress --inline --display-chunks
- And the Prod script:
$(npm bin)/webpack --config webpack.production.js
- Currently there is only one ‘entry point’ defined as ‘app’. This will need to be modified depending on the entry point or bootstrap script.