This repository demonstrates basic use of webpack-rails in a Rails 4.2 application.
Even though it demonstrates webpack-rails coexisting with sprockets, sprockets is not required or used by webpack-rails.
git clone https://github.com/mipearson/webpack-rails-demo.git
cd webpack-rails-demo
bundle install
npm install
foreman startThen open localhost:3000 in your browser. If everything is working, you should see "Sprockets works!" and "Webpack works!"
- Created new rails project:
rails new --skip-keeps --skip-active-record --skip-spring --skip-turbolinks --skip-test-unit webpack-rails-demo - Remove files, gems unnecessary for the demo
- Added
webpack-railsto theGemfileand ranbundle install - Ran
bundle exec rails generate webpack_rails:install - Added controller, routes and views for "Welcome" page
- Added sprockets-based javascript for "Welcome" page
- Edited
webpack/application.js - Added
*webpack_asset_pathstoindex.html.erbto load webpacked javascript - Ran
foreman start - Opened localhost:3000, confirmed that both Sprockets & Webpack are loaded