How to Set Up a React App for Continuous Integration

React apps need to be built and packaged up for deployment before we can think about sending them off to a hosting platform. This lessons covers how to build your React apps, ready for deployment.

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the Beginner's Guide to Real World React course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to Beginner's Guide to Real World React, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Beginner's Guide to Real World React

Lesson 2 - Building an app to deploy. Once we're working locally, we're not often concerned with performance or security or how things are being built and run. A lot of this is taken care of by the tuning we use and we're in a secure environment on our local machine, a machine that's usually dedicated to running this local dev server with only us a single user accessing it. With a tool like Create React app behind the scenes there is a heavily configured instance of Webpack which is bundling our code and serving it on a local URL like Local host, Par 3000 and hot swapping any changes. However, if we were to just stuff all this code into a hosting environment and have it run in, we'd find that over time it would get less performance. Things like Optimization, Minification, CSS Cleanup and other production ready processes would be skipped, potentially exposing our users to very rough code. And that's if the code would run at all. Some people like Webpack or Parcel do much more than just minifying and optimizing code, they make sure it works in the first place. Out of the box a lot of modern JavaScript doesn't run reliably in all browsers and environments. Some of the code we write is not supported in some browsers and tools like Babel.js are usually employed to transform this code into a backwards compatible flavor or polyfill to ensure that it works smoothly. Building and processing the code before deployment also allows us to chunk up the code into smaller parts and link together only the required parts of some JavaScript, say, for certain pages. We also tree-check our code to remove dead weight, run posts, CSS rules and transforms and basically smooth out any rough edges before we let it loose on our fans. But how do we build our projects? The process of building our applications and websites involves running a separate set of scripts, tools and processes on our code before we send it to a hosting service . If we take a look back at our most recent project from Module 4 and open up the package.json file you'll see the following section. We've been using Yarn's start for running our apps locally on some address like local host 3000 but when it comes time to build our code ready to deploy it's Yarn build that we'll need to run. So let's give it a try. Back in our project we'll open our terminal and we'll type the following command, Yarn build. We'll see some brief messages and then nothing. Let's take another look at the project directory. You should see a folder "Build" here and have a look in there and you'll see a few new files and folders especially in the JS folder. This is where there are a number of .js files. This is our app. This build folder is the one we'll want to deploy in the coming lessons as it holds the minified optimized code that our hosting provider will be able to serve our visitors. Continuous deployment and integration. Continuous deployment and integration is often shortened to CI and CD. Continuous deployment is a broad term that encapsulates the processes that happen when new code is committed to a code base. Broadly speaking it describes an often automated environment that flows like this. Code is checked into one or more version branches that are being watched by the CI/CD environment for changes, the changes noticed by the CI/CD environment. Automated tests are usually run next, unit tests or integration tests. On a successful test run a new build is started. Whatever build commands we have are run. On a successful build the built processed package code is collected and deployed to one or more hosting environments. In the next lesson we'll be setting up a simple CI/CD environment on Netlify to host our furry friends gallery. In reality CI/CD environments can be very complex beasts and are often managed by dedicated teams broadly grouped under the name DevOps. It's not imperative that you have a detailed knowledge of how to build and deploy your apps and sites at this level, but even having a basic grasp of the concepts and some experience with the process involved will make it easier for you to communicate with Dev Ops teams in your workplace. Now that we've got an idea with the concepts involved in building and deploying our apps and websites let's start deploying our very own project in the next lesson. [BLANK_AUDIO]