Create a React App Without Using npx create react app command

Today we’re going to see how we can create a React App without using the command npx create-react-app.

Check out the TECH IN 5 MINUTES channel :

🕔 Timeline :
00:00:00 – Intro
00:03:30 – Setup React project
00:08:26 – Install babel dependencies
00:11:02 – Install Webpack dependencies
00:12:23 – Webpack configuration
00:19:53 – Run webpack server
00:21:46 – Change Webpack server port

🌍 Social Media Links.
◾ Facebook :
◾ Twitter :
◾ Instagram :
◾ GitHub :

🤝 Suppport the Channel
Paypal :
Buy Me a Coffee:

God explains says hi today we're going To talk about how to create react app Without using npx Create react app so What do we need to create react app we Need node.js Babel webpack and face code So I'm going to talk a little bit about Each one of these so for node.js it's a JavaScript runtime and this means that You can run JavaScript on your machine Without the need of using a web browser Also when you install node.js this comes With the node package manager in PM that We use to install all the dependencies That we need for our project now for Babel it's a transpiler or a trans Compiler and this means simply a Converts a type of source code to Another type of source code so for Example when creating react app we use React and we use the newer ecmascript Features we can use typescript Etc and all of these is not supported by All the browsers for example when you Create a react component use GSX and GSX Here is Javascript and HTML both in the Same file and the browsers doesn't Understand that code so we need to use Babel to transpile or to transcompile That code into JavaScript also we Transpile this code here into all JavaScript so we can make sure that all The old browsers can also understand our Code and now for webpack which is a Bandler so when we need we pack so when

We create a react app we don't put all The app code in a single file but we put Them in separate files let's say we need To create react applications so we're Going to create this app.js file and We're not going to put all the code Inside that file so we're going to Create other components and that's the Whole idea behind react GS so we're Going to create the home navbar footer Components and then we're going to use The ecmascript module system or we're Going to use import to import these Files these modules into the app.js and Also these components can use Imports in Both other components well not all the Browsers understand or support the Import system so what we need to do here We need to use the webpack to combine These files here all the files into one Single file that's going to work in all The browsers and last for the code Editor I'm going to use vescode And now before we go and start creating Our react app from scratch I want to Suggest a very useful channel the Channel name is Tech in five minutes and As the name suggests they make five Minutes length videos about tech they Bring insights to the world of Technology Internet of Things software Development and more so don't forget Guys to check it out I'll leave the link Down in the description well without

Further Ado let's start with the first Step in creating our react app Now let's go and see that react so first I need to create a folder here So I'm going to call this react app And then I'm going to open this code and Drag and drop the folder Now I need to initialize a node project So I'm going to open a new terminal here And then I'm going to run npm In it then Dash y So this will create a package.json with The all the information needed for our App now I'm going to go and create some React files so I'm going to create a Folder called public and inside we're Going to need a Index.html file Also I'm going to create a search file So this is where I'm going to create my Components so I'm going to create a Component called and you can see It starts with a capitalized so this is A react component now in root of my Folder or inside the source I'm going to Create an Index.js file now inside my index.js File I will need to go and import react And also I'm going to import From react Dom I'm going to import The method a method called create root And this will initialize a react app on The client now I didn't install yet

React and react Dom so let's go and open Our terminal and then run npm install And dash dash save I'm going to install Reacts and react Dom I'm gonna hit save Well now you can see we have here a node Modules folder and also we have in our Package.json a some dependencies react And react Dom so now I can use them here Well the first thing I need to do is I'm Going to create a container for my app So I'm going to go to my public folder Then inside my Index.html I'm going to create a basic HTML code I'm going to change the title To react app and then here I'm going to Add a Dev with the class or with the ID Root And then I'm gonna hit save then go back To my index.js then select this Dev here So I'm going to use Document Dot get element by ID and then I'm gonna Pass in the ID root here to this method Now I'm going to create a root and then Use and create root here And I'm gonna pass in the container here And now I'm going to use the root render Method to render my app So the app here is the component inside My source folder so I need to First go And import that so I'm going to go Inside my search folder and then up and I shall call this app

And now I'm going to go to to Create my app and I'm going to use rfce Here hit enter and this will create my Component so I'm just going to go and Change this to react React up then without Npx create React App and this is what we'll see when we Run our app so we can't do that yet Because this is GSX the browser doesn't Understand this code here so we need to Use payable to transpile this code here And also we need to put all these files Here into one single to combine them Which means to create a bundle of these Files and that's where we need to use The webpack so let's move on to the next Step Now it's time to go and install all the People dependencies I'm going to need For our react app so I'm just going to Go here and close these files then I'm Going to open a new terminal now I'm Going to run npm install we're going to Need Babel Core so this is the main package that we Need for uh to use Babel and then we Need Babel slash preset Dash e and V and this is what we need to Use to transpile igma script sex JavaScript to all JavaScript that's Going to be supported by other browsers Then we're going to install at

Payable then slash press set Dash react so this is what we're going To use to transpile react code GSX code Into JavaScript it's going to be Supported by other Browsers and now I'm going to need to Install Babel Dash Loader so this is what we're going to Use when we set up webpack so when we Set up webpack we need to use Babel to Transpile the code before we bandlit With webpack and now the last package is Optional so you don't need to install This so you just want to install Babel Slash cell I if you want to transpile Your code using the command line so you Don't need to install this when using When creating a react app now I'm just Gonna go and say dash dash say live Dash Dev to install these dependencies as Dev Dependencies so I'm going to hit enter Now after the install of the Dependencies has finished now let's go And take a look on the package.json file So you can see here that now we have These Dev dependencies and we have all The Babel dependencies or packages we Need for our react app now let's move on To the next step And now it's time to install the webpack Dependencies so I'm going to close this File here then open a terminal and then Use npm install and I'm going to install The webpack package this is the main

Package that we need to install in order To use webpack and then I need to Install web Pack CLI to run webpack Commons on the Command line and also I need to install The web pack Dev server and this is the webpack Server that we need to use as a server In development if you are familiar with Nodemon or live server that's gonna be The same now I'm going to install these As the dependencies so save Dash Dev or Just Dash capital D and then I'm gonna Hit save Foreign Pack packages it's time to go and Configure webpack Now it's time to configure webpack so I'm going to root of my uh application And I'm going to create a file called Web pack Dot And I'm going to export the Configuration as an object so I'm going To use here module that exports Equals that object and the first thing We're going to set here is the mode so This could be this could be a Development or production so because we Are in development I'm going to set this To development And now we need to tell we pack the Entry pound so we need to give it the File from where it starts to look for All the files it needs to bundle so in

This case it's going to be the index.js And it's going to look for all the Imports from there to like look for the Files that it needs to bundle so I'm Going to use here The index.js Now I'm going to go and set the output So what I want to save the files So I'm going to use here a path Or to set a path and to do that I'm Going to use the built-in module node Module path so I'm going to Go and say const path equals so I want To import that using require Path so we don't need to install this so Path that resolve and then I'm going to Choose the directory name so this Directory here and then I want to save These in a folder called test And that's it now before we bundle the Files We need to tell we pack to use Babel to Transpile the code so I'm going to use Here module it's going to be an object Then inside I need to add a property Called rules which is an array so you Can add as many rows as you want so I'm Going to add a rule for JavaScript and Jsx file so I'm going to look for those Files using this test which is going to Be a regex so I'm going to look for all The files that That ends with Js Or GSX

Ends means a dollar sign in regex so all The files that ends with JS or jsx must Be transpiled then bundled so now I'm Going to exclude some files because node Modules folder here has JavaScript files So I need to exclude that so I need to Say nodes modules this must be excluded And here I must say what is the loader I Want to use which is Babel loader here So this is going to be a an object and I'm gonna set this a property loader to Babel loader which we have already Installed and then I need to also Mention the presets so I'm going to use Options here it's going to be an object With a presets property so this process Prop is going to be an array now I'm Going to use the Babel slash press set Dash a and v This is for transpiling as sex and later To all JavaScript that is support by Older browsers now I also need to Use the preset to transpile GSX Files So they will preset Dash react and we Are done with a transparent decode using Babel now I'm going here To the output and once the once the Files are bundled I want the file name To be Index Bundle Dot JS if you don't set this a random Name is going to be generated so I want

To bundle the name or the files and the Name of the band Loop must be in Expanded.js now what is the use of this And expand lag GS after it span after All the files have been bundled so The index for our application to Work we need to put this JavaScript in This index.h demo that it resides inside Our public folder so if I go to Index.html I need to add a script tag Here that And the source must be the index The index Dash bundle dot GS so I don't Need to do this manually we need to go And use a plugin so that plugin is going To be So I need to use plugins here it's going To be an array and I need to set a new HTML webpack plugin so HTML webpack Plugin will check in this index.html as A template and it will add to it a Script tag just like we did manually and The search is going to be this and so here I need to add an Object and then I need to set a template Here and it's going to be set to path Again dot join And I'm going to use the chair name then The a public folder so the Index.html is inside our public folder And then the name of the file which is Index.html And I'm gonna hit save now I need of Course to go and

Import this here so I'm just gonna go Here it's imported automatically so HTML Pack plugin require HTML webpack plugin Now we need to go and install this using Npm so I'm gonna go here and open the Terminal and then use npm install I'm Going to install this as a Dev Dependency and then the name of the Package now I'm gonna hit enter And now that this has been completed and We have configured webpack now it's time To run the server To run the webpack server we need to go And like say npm run Dev and this will Run the server but first we need to go Into our package.json here and under the Scripts we need to add these scripts Here so Dev It's going to be equal to width back Then serve And I need also to add another script to Build my application for production it's Going to be set to webpack now I'm going To hit save now if I came here and hit Enter I hope we did we don't face any problems Here Yeah and it says the project is running At localhost 880 so which means Everything is compiled successfully and We should just go and hit Ctrl click to Open Our app Now you can see here that it says react

Up without impacts create react app Which is this file here which is our app So I'm going to just change this to Hello And you can see that the page has been Refreshed automatically and the changes Has been applied and that's how you can Create a react app without using npx Create react app well I still have the Last path in this tutorial which is set Up in the uh the server here so what if You want to use a different port than 8080 so that's what we need to do next Now let's go and change our webpack Server Port so I'm going to go to our Webpack config.js and somewhere here I'm Going to use the dev server Dev server I'm going to use here Ports and set it to like 5 000. I'm Going to hit save now let's open our Terminal let's go and stop this one here Using Ctrl c y Now let's go and run Npm run Dev And You can see now that the port has been Changed to 5 000. now if I click on this Ctrl click You can see now that our app is served At localhost 5000 and that's it for this Tutorial I hope you liked it don't Forget to like comment share and Subscribe see you in another tutorial

Thank you

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *