Lab 1: Creating a New Project
Objectives
- Create a new React project (app)
- Open the new project
- Review the default project structure
Steps
Create a new React project
As part of the course setup, you created a
codedirectory for the course (somewhere on your computer that you would easily remember). If you haven't created acodedirectory yet please do that now.Open a
command prompt(Windows) orterminal(Mac).Change the current directory to your
codedirectory.Run ONE of the following commands:
If you want to use
npmas your package manager.npmnpx create-react-app keeptrack --use-npmIf you want to use
Yarnas your package manager.Yarnyarn create react-app keeptrackyarn createis available in Yarn 0.25+
Open the new project
Change the current directory (
cd) to the directory you created in the last step.cd keeptrackOpen the
keeptrackdirectory in your editor of choice.If you are using
Visual Studio Codeyou can run the following command in your terminal:code ....
coderefers to Visual Studio Code and.means current directoryif
codeis not in yourcommand prompt(Windows) orterminal(Mac)PATH- in
Visual Studio CodechooseView>Command Palette> Shell Command: Install 'code' command in PATH
- in
Review the default project structure
Take a few minutes to go over the default project structure. Below are some files to look at:
package.jsonpublic/index.htmlis the page templatesrc/index.jsis the JavaScript entry point
For the project to build, the last two files above files must exist with exact filenames:
You can delete or rename the other files.
You may create subdirectories inside
src. For faster rebuilds, only files insidesrcare processed by Webpack. You need to put any JS and CSS files insidesrc, otherwise Webpack won’t see them.Only files inside
publiccan be used frompublic/index.html.