Add Webpack to a Rails 4.2 app with the Webpacker gem | Ryan Bosinger

Add Webpack to a Rails 4.2 app with the Webpacker gem

Add gem:

gem 'webpacker', '~> 2.0'
bundle install

Run either normal or React-ready install:

rake webpacker:install
rake webpacker:install:react

Add jQuery if you still need it:

yarn add jquery

Add expose-loader:

yarn add expose-loader -D

Change config/webpack/configuration.js:

module.exports = {
  settings,
  env,
  loadersDir,
  output,
  rules: [{
    test: require.resolve('jquery'),
    use: [{
      loader: 'expose-loader',
      options: '$'
    }]
  }]
}

Cheers,
Ryan