Recently, I contributed to react.dev repo and noticed how their CI/CD pipeline was structured. Clean, automated, and resilient. It made me think: what are the essentials every React/Next.js project should have in its pipeline?
Letβs explore the best practices π.
π― The problem with "Basic pipelines"
Many teams set up basic commands
- Install dependencies
- Build project
- Deploy
Sounds fine right? You are missing many critical points.
- Bundle size related issues
- Broken builds
- Inconsistent environments
- Slow feedbacks
The list doesn't end here.
The point is: a fragile pipeline leads to fragile releases.
𧬠Essential Steps in a Pipeline
A solid React/Next.js pipeline should go beyond just install, lint, test, build.
Hereβs an extended GitHub Actions workflow you can adapt to your projects:
name: CI
on:
push:
branches: [ main ]
pull_request:
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@v3
# Setup Node.js
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
# Clean install dependencies
- run: npm ci
# Lint checks (fail fast)
- run: npm run lint
# Type checking with TypeScript
- run: npm run type-check
# Unit tests with coverage
- run: npm run test -- --ci --coverage
# End-to-End tests (optional: Cypress/Playwright)
- run: npm run e2e
# Build the Next.js app
- run: npm run build
# Run Next.js static analysis
- run: npm run analyze
# Check bundle size (with e.g. size-limit)
- run: npm run size
# Lint commit messages (Conventional Commits)
- run: npx commitlint --from=HEAD~1 --to=HEAD
# Upload build artifacts (optional)
- uses: actions/upload-artifact@v4
with:
name: next-build
path: .next
π Best Practices
- Use npm ci over npm install β reproducible, clean installs.
- Linting as a first step β fail fast on code style issues.
- Unit + integration tests with coverage β reliability guaranteed prior to merging.
- Preview deployments (e.g., Vercel, Netlify) β every PR receives a live environment.
- Cache dependencies between runs β faster pipelines.
- Secrets management β use environment variables safely (no .env leaks!).
- Bundle analysis β track performance are monitored in PRs.
π Bonus Steps Worth Adding
- Type checking (tsc --noEmit) β prevents runtime bugs.
- Playwright / Cypress e2e tests β simulate real user flows.
- Accessibility checks (axe-core, Lighthouse CI) β catch issues early.
- Storybook build β visual regression testing for UI components..
π Conclusion
A bad or poor CI/CD is no more tolerated. Is a powerful tool to leverage the development process.
A solid pipeline should be your safety net
Good pipelines include:
- Fast feedback
- Error prevention
- Consistent environments
- Bundle monitoring Of course, pipelines evolve daily, but that's not an excuse to ignore. π The goal isn't perfection, is continuous improvement.
π Thank you for reading.
This is my first article.
If you found this useful let me know and share it.
See you around!
Top comments (0)