If you're looking for a quick start, here's the simplest way to begin
npx create-react-app my-app
cd my-app
npm start
For those willing to tackle a more complex setup, consider this alternative method
mkdir my-app // create directory
cd my-app
npm init -y //create package.json
npm install react react-dom //install react and react-dom
touch index.js index.css
To start writing code, edit the index.js file with something like this
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
class App extends React.Component{
render(){
return(
<div>Hello World</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'))
Next, set up Babel by running the following command
npm install --save-dev @babel/core @babel/preset-env @babel/preset-react webpack webpack-cli webpack-dev-server babel-loader css-loader style-loader html-webpack-plugin
touch webpack.config.js
Customize your webpack configuration as needed
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry : './my-app/index.js',
output : {
path : path.resolve(__dirname , 'dist'),
filename: 'index_bundle.js'
},
module : {
rules : [
{test : /\.(js)$/, use:'babel-loader'},
{test : /\.css$/, use:['style-loader', 'css-loader']}
]
},
mode:'development',
plugins : [
new HtmlWebpackPlugin ({
template : 'my-app/index.html'
})
]
}
Lastly, add Babel presets and npm scripts for building (build) and running (dev) your project in package.json
"main": "index.js",
"babel": {
"presets": ["@babel/preset-env", "@babel/preset-react"]
},
"scripts": {
"build": "webpack",
"dev": "webpack-dev-server --open"
}