Giter Site home page Giter Site logo

porkbuns / react_webpack_rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rdnewman/react_webpack_rails

0.0 5.0 0.0 606 KB

Simple react-webpack-rails integration

License: MIT License

Ruby 65.10% Shell 0.21% HTML 16.75% JavaScript 16.71% CSS 1.24%

react_webpack_rails's Introduction

ReactWebpackRails

Rails - Webpack setup with React integration.

Inspired and partially based on https://github.com/reactjs/react-rails/ this gem provides generators and helpers that makes react-webpack-rails integration easy.

Installation

Add this line to your application's Gemfile:

gem 'react_webpack_rails'

Execute:

$ bundle

Or install it yourself as:

$ gem install react_webpack_rails

Then run installation:

$ rails g react_webpack_rails:install

This will create following files:

├── app
│   ├── react
│   │   ├── components
│   │   │   ├── hello-world.jsx
│   │   │   └── hello-world-test.jsx
│   │   └── index.js
│   ├── views
│   │   └── layouts
│   │       └── _react_hot_assets.html.erb
│   └── assets
│       └── javascripts
│           └──react_bundle.js
├── webpack
│   ├── dev.config.js
│   ├── hot-dev.config.js
│   ├── production.config.js
│   └── tests.config.js
├── .babelrc
├── karma.conf.js
├── package.json
└── webpack.config.js

Establish the node packages (may take a few moments)

$ npm install    # you may see warnings to consider updating the provided package.json file with license and repository

Make sure you have webpack installed globally:

$ npm install webpack -g

Generate react_bundle for first time:

$ webpack

And require integration and bundle files in application.js

//= require react_integration
//= require react_bundle

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';
registerComponent('customComponentName', Component);

Use it in rails view

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

Use it in javascript file

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

Development

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

Or manually:

$ webpack -w --config YOUR_CONFIG

Production

Run webpack in production mode before compiling assets using script:

$ npm run build

or manually:

$ webpack -p --config YOUR_CONFIG

Deployment

Check docs/deployment.md

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/netguru/react_webpack_rails.

License

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

react_webpack_rails's People

Contributors

hfwang avatar jerefrer avatar marcinkornek avatar mxaly avatar rdnewman avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

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.