How to do it...

Let's go ahead and create our basic application. If you had to set up a project purely by hand, you'd find yourself having to deal with many different tools, such as Babel for transpiling, ESLint for code checks, Jest for testing, or Webpack in order to pack all of your application together, instead of having to send dozens or hundreds of individual files over the web. However, nowadays, there is a much simpler tool, create-react-app, that can deal with this chore and get you set up for React development in a jiffy. The key selling point is zero configuration, meaning that some reasonable good choices for both development and production builds have been selected, and you can directly move on to writing code, not really caring about myriad configuration details.

For people in the know, create-react-app is known as CRA, and that's the name we'll be using. By the way, CRA is not the only possible way to create a project; for example, react-boilerplate (at https://github.com/react-boilerplate/react-boilerplate) provides an alternate solution, but the chosen set of packages and tools are more suited to experienced React developers.

To create the basic structure (which we'll explain later on) we'll use npx to run the application creator tool, as shown in the following code. Since we are at Chapter 6, let's (imaginatively!) name our project chapter06

> npx create-react-app chapter06
Creating a new React app in /home/fkereki/JS_BOOK/modernjs/chapter06.

Installing packages. This might take a couple minutes.
Installing react-scripts...

...many lines describing installed packages, snipped out...

Success! Created chapter06 at /home/fkereki/JS_BOOK/modernjs/chapter06
Inside that directory, you can run several commands:

npm start
Starts the development server.

npm run build
Bundles the app into static files for production.

npm test
Starts the test runner.

npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

cd chapter06
npm start

Happy hacking!

If you are curious, npx is similar to npm, but it executes a binary command, which is either found in your node_modules directory, or at a central cache, even installing any packages it might need to run. For more information, go to its GitHub page at https://github.com/zkat/npx, or better yet, read an article by npx's creator, Introducing npx: an npm package runner at https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.82.253