No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Integration tool for React + Webpack with Rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.11
~> 5.0
~> 10.0
 Project Readme

React::Webpack::Rails

A simple installation tool for getting up and running with React + Webpack in Rails.

* This is still in the early stages of development, and is experimental. Feedback is appreciated, and pull requests are welcome.

OVERVIEW

This is a minimalist approach to integrating React and Webpack with Rails. There's nothing really hidden in the gem. The point is to be transparent about what is being added to your app and why.

There are several goals for this gem:

  • Provide a lightweight gem for integrating React and Webpack to Rails
  • Easy asset compiling for development and production
  • Fluid development workflow
  • Easy npm module integration
  • single step server for development
  • single asset compilation for deployment

INSTALLATION

Add this line to your application's Gemfile:

gem 'react-webpack-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install react-webpack-rails

GENERATOR TOOL

* not currently supporting HAML

$ rails g react:webpack:install

WHAT THIS GENERATES

EMPTY DIRECTORIES

  • client/components
  • app/assets/webpack

BASE FILES

  • webpack.config.js
  • .babelrc
  • app/helpers/react_helper.rb
  • client/index.js
  • Procfile
  • lib/tasks/assets.rake

GEMS

  • foreman

* you can skip immediate installation

NODE MODULES

  • babel-core
  • babel-loader
  • babel-preset-es2015
  • babel-preset-react
  • classnames
  • react
  • react-dom
  • webpack

* you can skip immediate installation

APPENDING WEBPACK WATCH TASK

  • "watch": "webpack --watch --colors --progress"

APPENDING ASSETS INTO THE PIPELINE

  • javascript_include_tag to app/views/layouts/application.html.erb
  • Rails.application.config.assets.precompile += %w( bundle.js ) to config/initializers/assets.rb

DEVELOPMENT

The generator installs Foreman and adds a Procfile to fire up Webpack and the Rails server in a single command:

$ foreman start

You can also run these separately if you'd like.

npm run watch
rails server

If everything went well, you should be able to view your app at http://localhost:3000

You can add your components to client/components/ and be sure to list them in client/index.js

You can call components in the view with an erb tag for your components and props: <%= react_component :Dropdown, listItems: [1,2,3,4] %>

PRODUCTION

A rake task for precompiling the webpack assets is added by the generator. This essentially adds the Webpack/Babel transpiling to the precompilation task that runs when you deploy to production. So you should never need to have two separate build tasks.

CONTRIBUTING

Bug reports and pull requests are welcome on GitHub at https://github.com/alanbsmith/react-webpack-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

LICENSE

The gem is available as open source under the terms of the MIT License.