setup react js code example

Example 1: install react js

npx create-react-app <appname>  //  eg:  npx create-react-app blog
cd <appname>  // cd blog
npm start  //runs on localhost:3000

Example 2: reactjs install

npm install -g create-react-app -> install create react app tools
create-react-app app01 -> create your first projects app001

Example 3: react js installation

npx create-react-app my-app
cd my-app
npm start

Example 4: how to install react js

C:\Users\username\Desktop\reactApp>npm install webpack webpack-dev-server webpack-cli --save

Example 5: how to install react js

C:\Users\username\Desktop\reactApp>npm install babel-core babel-loader babel-preset-env 
   babel-preset-react html-webpack-plugin --save-dev

Example 6: setup the react on local machine

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
   entry: './main.js',
   output: {
      path: path.join(__dirname, '/bundle'),
      filename: 'index_bundle.js'
   },
   devServer: {
      inline: true,
      port: 8001
   },
   module: {
      rules: [
         {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
               presets: ['es2015', 'react']
            }
         }
      ]
   },
   plugins:[
      new HtmlWebpackPlugin({
         template: './index.html'
      })
   ]
}