Js part of react_webpack_rails - webpack based React & Rails integration.
npm install eh-rwrIf 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.
Add this line to your application's Gemfile:
``ruby`
gem 'react_webpack_rails'
Execute:
$ bundle
Then run installation:
$ rails g react_webpack_rails:install
read more about install generator
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.
:
(it's not needed when you want to use just webpack in watch mode without hot-reloading)
`erb
<%= render 'layouts/react_hot_assets' %>
`#### Register component in index.js
`js
import Component from './components/some-component';
RWR.registerComponent('customComponentName', Component);
`#### Use it in rails view
`erb
<%= react_component('customComponentName', { user: User.last }) %>
`#### Use it in javascript file
`js
const element = $('#my-element');
RWR.renderComponent('customComponentName', {user_id: 1}, element);
`#### Render component in controller
`ruby
def action_name
render react_component: 'customComponentName', props: { user_id: 1 }
end
`$3
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
$ 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
See the contribution guide.
The gem is available as open source under the terms of the MIT License.