5 Steps to Reduce Your React App CI/CD Build Minutes (2024)

5 Steps to Reduce Your React App CI/CD Build Minutes (1)

Introduction

CI/CD pipelines are great for automation and are an essential part of any software delivery process. This post covers React, but the principles can be applied to any application stack.

The Problem: As your application grows in size your build minutes will also start to balloon. As well as the raw cost of build minutes (eg: GitLab, Azure DevOps, GitHub) build times can also affect productivity, validation cycles, and ultimately speed to market.

Here’s my list of 5 things to help reduce pipeline build minutes for your React application:

  1. Enforce linting rules and code styles in your IDE
  2. Catch lint, code style and unit test errors locally
  3. Catch missing environment variables at build time
  4. Cache dependencies
  5. Review your bundling tools
1) Enforce linting rules and code styles in your IDE

“Developers who get feedback from their IDE don’t waste valuable build minutes”

Use VS Code and install the following extensions to get developers to resolve linting and code style issues before fail in your pipelines:

2) Catch lint, code style and unit test errors locally

After the IDE extensions have done some heavy lifting, the next line of defence is githooks. These can be used to trigger automation locally, rather than blocking your CI/CD pipelines with broken builds.

Husky is a simple tool to help you configure your githooks.

3) Catch missing environment variables at build time

If your using CRA you’ll know how to add custom environment variables to your project.

As you project grows in size and complexity the number of environment variables you need will also grow. This will include: external API endpoints, number of environments, number of developers in your team(s).

Don’t wait for your production build to find our environment variables are missing, catch them at the very start of your build pipeline.

Here’s a simple Node.js script to add as a first step in your pipeline to check all required environment variables have been configured:

const requiredVars = [ "REACT_APP_BASE_URL", "REACT_APP_CMS_API_URL"];const getMissingEnvVars = (envVars) => { const missingEnvVars = []; envVars.map(envVar => { if(!process.env[envVar]){ missingEnvVars.push(envVar); } }); return missingEnvVars;};missingEnvVars = getMissingEnvVars(requiredVars);if (missingEnvVars.length > 0) { console.error( `ERROR: Missing environment variable(s): ${missingEnvVars.join(", ")}` ); process.exit(1);}process.exit(0);

TIP: You could also externalise your required environment variables in a JSON file and run a similar check at runtime from within your application.

4) Cache dependencies

Use npm ci to cache your npm dependencies:

5) Review your bundling tools

esbuild could significantly (10-100x) reduce your build time.

Use craco (Create React App Configuration Override) to replace your CRA Webpack configuration.

Summary

Reducing the number of broken builds and decreasing build time will make your development team more productive and increase your speed to market.

Check out these posts if you’re interested in automation with CI/CD:

5 Steps to Reduce Your React App CI/CD Build Minutes (2024)
Top Articles
The White Lotus in Sicily: discover the stunning locations! | Isula Travel
Easy Google sign-in for Samsung account on your Galaxy device
Lakers Game Summary
Ups Dropoff Location Near Me
Inducement Small Bribe
Dricxzyoki
Lifewitceee
Greedfall Console Commands
Team 1 Elite Club Invite
Evil Dead Rise Showtimes Near Massena Movieplex
Gabrielle Abbate Obituary
Holly Ranch Aussie Farm
Theycallmemissblue
Ivegore Machete Mutolation
Drago Funeral Home & Cremation Services Obituaries
Fear And Hunger 2 Irrational Obelisk
Craigslist Malone New York
Lesson 8 Skills Practice Solve Two-Step Inequalities Answer Key
How To Cut Eelgrass Grounded
Stardew Expanded Wiki
Why Is 365 Market Troy Mi On My Bank Statement
Finalize Teams Yahoo Fantasy Football
Iroquois Amphitheater Louisville Ky Seating Chart
Keci News
Lacey Costco Gas Price
Bayard Martensen
Annapolis Md Craigslist
A Man Called Otto Showtimes Near Carolina Mall Cinema
Darknet Opsec Bible 2022
Nurofen 400mg Tabletten (24 stuks) | De Online Drogist
Duke Energy Anderson Operations Center
Taktube Irani
Navigating change - the workplace of tomorrow - key takeaways
Emerge Ortho Kronos
Vision Source: Premier Network of Independent Optometrists
877-292-0545
Sam's Club Gas Prices Deptford Nj
Shane Gillis’s Fall and Rise
Academy Sports New Bern Nc Coupons
Clima De 10 Días Para 60120
Nami Op.gg
boston furniture "patio" - craigslist
Pink Runtz Strain, The Ultimate Guide
60 Days From May 31
Iupui Course Search
20 Mr. Miyagi Inspirational Quotes For Wisdom
Menu Forest Lake – The Grillium Restaurant
Tyco Forums
Lesly Center Tiraj Rapid
German American Bank Owenton Ky
Definition of WMT
Brutus Bites Back Answer Key
Latest Posts
Article information

Author: Dr. Pierre Goyette

Last Updated:

Views: 5474

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.