From 4775d8bc49055e1fd074c10745d38b60e960e710 Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Wed, 26 Oct 2022 17:55:33 +0300 Subject: [PATCH] Update documentation --- docs/getting-started.md | 16 +++++++---- docs/guides/tutorial.md | 63 +++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index c953a5071..4e4a37f52 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -11,13 +11,20 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl *See also [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/).* -1. Add the `react_on_rails` gem to Gemfile: +1. Add the `shakapacker` and `react_on_rails` gem to Gemfile: ```bash + bundle add shakapacker bundle add react_on_rails --strict ``` -2. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`). +2. Run installation command for webpacker: + + ```bash + rails webpacker:install + ``` + +3. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`). 3. Run the generator: @@ -27,9 +34,8 @@ Note, the best way to understand how to use ReactOnRails is to study a few simpl 4. Start the app: - ```bash - rails s - ``` + - Run `./bin/dev` for HMR + - Run `./bin/dev-static` for statically created bundles (no HMR) 5. Visit http://localhost:3000/hello_world. diff --git a/docs/guides/tutorial.md b/docs/guides/tutorial.md index 51e10ac88..5af7e8976 100644 --- a/docs/guides/tutorial.md +++ b/docs/guides/tutorial.md @@ -45,25 +45,22 @@ Then we need to create a fresh Rails application as following. First be sure to run `rails -v` and check you are using Rails 5.1.3 or above. If you are using an older version of Rails, you'll need to install webpacker with react per the instructions [here](https://github.com/rails/webpacker). ```bash -cd +# For Rails 6.x +rails new test-react-on-rails --skip-javascript -# Any name you like for the rails app -# Skip javascript so will add that next and get the current version -# This is for Rails 7 +# For Rails 7.x rails new test-react-on-rails --skip-turbolinks --skip-javascript cd test-react-on-rails ``` ## Add the shakapacker and react_on_rails gems -To avoid issues regarding inconsistent gem and npm versions, you should specify the exact versions +We recomment to use latest version of these gems. Otherwise, specify the exact versions of both the gem and npm package. In other words, don't use the `^` or `~` in the version specifications. -_Use the latest version for `react_on_rails` and `shakapacker`._ - -``` -gem 'react_on_rails', '13.0.1' # prefer exact gem version to match npm version -gem 'shakapacker', '6.4.0' # prefer exact gem version to match npm version +```bash +bundle add react_on_rails +bundle add shakapacker ``` Note: The latest released React On Rails version is considered stable. Please use the latest @@ -71,32 +68,34 @@ version to ensure you get all the security patches and the best support. ## Run the shakapacker (webpacker) generator -```terminal +```bash bundle exec rails webpacker:install ``` -**Let's commit everything before installing React on Rails.** +Commit all the changes so far to avoid getting errors in the next step. +```bash +git commit -am "Initial commit" ``` -# Here are git commands to make a new git repo and commit everything. -# Newer versions of Rails create the git repo by default. -git add -A -git commit -m "Initial commit" -``` + +Alternatively you can use `--ignore-warnings` in the next step. ## Run the React on Rails Generator -Install React on Rails: `rails generate react_on_rails:install`. You need to first git commit your files before running the generator, or else it will generate an error. +```bash +rails generate react_on_rails:install +``` + +You will be prompted to approve changes in certain files. Press `enter` to proceed +one by one or enter `a` to replace all configuration files required by the project. +You can check the diffs before you commit to see what changed. Note, using `redux` is no longer recommended as the basic installer uses React Hooks. -If you want the redux install: `rails generate react_on_rails:install --redux` +If you want the redux install, run: +```bash +rails generate react_on_rails:install --redux ``` -bundle exec rails generate react_on_rails:install -``` - -Enter `a` to replace all configuration files required by the project. You can check the diffs -before you commit to see what changed. ## Setting up your environment variables @@ -108,14 +107,18 @@ EXECJS_RUNTIME=Node Then run the server with one of the following options: -## Running with HMR -``` -foreman start -f Procfile.dev -``` +## Running the app -## Running without HMR, statically creating the bundles +### For HMR: + +```bash +./bin/dev ``` -foreman start -f Procfile.dev-static + +### Without HMR, statically creating the bundles + +```bash +./bin/dev-static ``` Visit [http://localhost:3000/hello_world](http://localhost:3000/hello_world) and see your **React On Rails** app running!