Giter Club home page Giter Club logo

react_webpack_rails's Introduction

ReactWebpackRails

Travis CI

!! DEPRECATED !!

Consider using Webpacker instead.

If you are looking for view helpers and/or redux integrations, see:

  1. react-rails (currently using webpacker)
  2. react-on-rails (migration to webpacker in progress, using forked version now)

Rails - Webpack setup with React integration.

This gem provides easy and convenient way to build modern JavaScript stack on top of Rails applications using Webpack and React.

Features

Plugins:

  • rwr-alt plugin that makes it possible to populate and share Alt stores between react component located in different parts of rails views.
  • rwr-redux allows to use redux state containers in a rails views.
  • rwr-react_router react-router integration.
  • rwr-view_helpers handy view helpers.

Installation

Add this line to your application's Gemfile:

gem 'react_webpack_rails'

Execute:

$ bundle

Then run installation:

$ rails g react_webpack_rails:install

read more about install generator

Babel

By default, react-webpack-rails uses Babel Stage 1 - Proposal. If you want to change the stage, you can do so in the .babelrc file. It is however not recommended to use Stage 0 in a production app, because the features present there can be dropped, which would break your application.

Usage

Check docs for detailed api description.

to use hot-reloading add partial in your application.html.erb to <body>:

(it's not needed when you want to use just webpack in watch mode without hot-reloading)

<%= render 'layouts/react_hot_assets' %>

Register component in index.js

import Component from './components/some-component';
RWR.registerComponent('customComponentName', Component);

Use it in rails view

<%= react_component('customComponentName', { user: User.last }) %>

Use it in javascript file

const element = $('#my-element');
RWR.renderComponent('customComponentName', {user_id: 1}, element);

Render component in controller

def action_name
  render react_component: 'customComponentName', props: { user_id: 1 }
end

Development environment

Run webpack in watch mode using script:

$ npm start

Run webpack in hot-auto-reloading mode using script (to use it you have to add react_hot_assets partial as mentioned before):

$ npm run start-hot-dev

If you are using server side render in components (it's enabled by default in generated example), run node server:

$ npm run rwr-node-dev-server

Production environment

Run webpack in production mode before compiling assets using script:

$ npm run build

If you are using server side render (it's enabled by default in generated example), run node server:

$ npm run rwr-node-server

Deployment

Check docs/deployment.md

Contributing

See the contribution guide.

License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.