Navigate to the directory where you want to create your project.
Create a new directory for your project and navigate into it:
bash코드 복사
mkdir my-react-app
cd my-react-app
Initialize a Git Repository:
Initialize a git repository in the project directory:
bash코드 복사
git init
Create a New React App:
Use the create-react-app command to set up a new React project. This will create a new React app with a basic structure and configuration.
bash코드 복사
npx create-react-app .
The . at the end tells the script to create the app in the current directory.
Install Additional Dependencies:
Depending on your project needs, you might want to install additional dependencies. For example, you might want to add a router for handling navigation:
bash코드 복사
npm install react-router-dom
Or if you're using TypeScript:
bash코드 복사
npm install typescript @types/node @types/react @types/react-dom @types/jest
Set Up ESLint and Prettier (Optional but Recommended):
Install ESLint for linting your code:
bash코드 복사
npm install eslint --save-dev
npx eslint --init
Install Prettier for code formatting:
bash코드 복사
npm install --save-dev prettier eslint-config-prettier eslint-plugin-prettier
Configure ESLint and Prettier by adding appropriate config files (.eslintrc.json and .prettierrc) to your project.
Create Initial Commit:
Stage all the files and create an initial commit:
bash코드 복사
git add .
git commit -m "Initial commit with React setup"
Push to GitHub (or other remote repository):
Create a new repository on GitHub.
Link your local repository to the GitHub repository:
bash코드 복사
git remote add origin https://github.com/yourusername/my-react-app.git
Push your code to GitHub:
bash코드 복사
git push -u origin master
Start Development:
Now, you can start the development server:
bash코드 복사
npm start
This will run your app on http://localhost:3000.
Building the Project for Production:
When you're ready to deploy, build the project:
bash코드 복사
npm run build
This will create a build directory with a production-ready version of your app.
Summary
Install Node.js and npm.
Set up your project directory.
Initialize a git repository.
Create a React app using create-react-app.
Install additional dependencies.
Set up ESLint and Prettier for code quality.
Create an initial commit and push to a remote repository.
Start development or build for production.
This guide helps you set up a React project from scratch and prepare it for collaboration via a git repository.
To build a React repository from scratch, you'll follow several key steps. Below is a guide to help you create a new React project and repository:
Step-by-Step Guide to Build a React Repository
Install Node.js and npm:
Set Up Your Project Directory:
Create a new directory for your project and navigate into it:
Initialize a Git Repository:
Initialize a git repository in the project directory:
Create a New React App:
Use the
create-react-app
command to set up a new React project. This will create a new React app with a basic structure and configuration.The
.
at the end tells the script to create the app in the current directory.Install Additional Dependencies:
Depending on your project needs, you might want to install additional dependencies. For example, you might want to add a router for handling navigation:
Or if you're using TypeScript:
Set Up ESLint and Prettier (Optional but Recommended):
Install ESLint for linting your code:
Install Prettier for code formatting:
Configure ESLint and Prettier by adding appropriate config files (
.eslintrc.json
and.prettierrc
) to your project.Create Initial Commit:
Stage all the files and create an initial commit:
Push to GitHub (or other remote repository):
Create a new repository on GitHub.
Link your local repository to the GitHub repository:
Push your code to GitHub:
Start Development:
Now, you can start the development server:
This will run your app on
http://localhost:3000
.Building the Project for Production:
When you're ready to deploy, build the project:
This will create a
build
directory with a production-ready version of your app.Summary
create-react-app
.This guide helps you set up a React project from scratch and prepare it for collaboration via a git repository.