Introduction
In this article, we will learn how to create Babel for React scratch setup with Webpack.
Steps
We’ll start with a React project.
Step 1
Now that we have Node and npm installed, we will create a new folder for our project, newreact.
Step 2
Initialize it as an Npm project
npm init -y

Step 3 - Installing Dependencies using NPM
Run the below command in the terminal:
npm i webpack webpack-cli --save-dev

Webpack is a tool that will bundle your code and its dependencies into a single
.js file.Let's install the Babel dependencies:
npm i @babel/core babel-loader @babel/preset-env @babel/preset-react --save-dev
What is Babel?
Babel is a toolchain mainly used to convert ECMAScript 2015+ code into a backward-compatible version of JavaScript in current and older browsers or environments.
Step 4 - Create Project Folder structure
Now, we will config the Babel. Let’s create a new file, (.babelrc)
- babel preset env for compiling modern Javascript down to ES5
- babel preset react for compiling JSX and other stuff down to Javascript.
npm i react react-dom
installing the HTML webpack plugin
npm i html-webpack-plugin html-loader --save-dev

Then update the webpack's configuration file:
- const HtmlWebPackPlugin = require("html-webpack-plugin");
- module.exports = {
- module: {
- rules: [{
- test: /\.(js|jsx)$/,
- exclude: /node_modules/,
- use: {
- loader: "babel-loader"
- }
- }, {
- test: /\.html$/,
- use: [{
- loader: "html-loader"
- }]
- }]
- },
- plugins: [
- new HtmlWebPackPlugin({
- template: "./src/index.html",
- filename: "./index.html"
- })
- ]
- };



Join the conversation! Your thoughts help the community grow.