備忘録。
Gem
- react-rails
- browserify-rails
npm_modules
- browserify
- browserify_incremental
- babelify
- babel-preset-es2015
- babel-preset-react
- babel-preset-stage-2
- react
- react-dom
- react-redux
- redux
- redux-thunk
以上をGemfile及びpackage.jsonでインストールする。
.babelrc
.babelrcに以下を記述
{
"presets": ["ec2015", "stage-2", "react"]
}
config/application.rb
config.browserify_rails.commandline_options = '-t babelify --extension=.jsx'
続いてreactをインストールする。
rails g react:install
components.js
window.React = require('react');
window.ReactDOM = require('react-dom');
window.Hello = require('./components/hello'); //Reactコンポーネント
こうするとnpmから入れたreactをヘルパーでよびだせる。
参考URL
http://qiita.com/suzan2go/items/24ef3320e04b8a84597f
http://qiita.com/imaimiami/items/f5362099533aefcdd2b4
http://qiita.com/kozo002/items/a276569e85395fce801e