Setting up an Angular 12 workspace with Nx and GitHub Actions

May 21, 2021

230 words

Post contents

In this episode of Nx After Dark, we're creating an Nx workspace for an Angular 12 app called Energy Insights. We're also setting up a GitHub Actions workflow and connecting it to Nx Cloud.

An embedded webpage:Nx After Dark: Setting up an Angular 12 workspace

Follow the instructions below to set up a similar workspace or browse the end result at github/LayZeeDK/energy-insights.

Prerequisites

  • Node.js 14.x
  • PNPM

Note that there's currently an issue with using Cypress with PNPM. Let me know if you figure out how to fix it. Until then, remove Cypress from the workspace or use either Yarn or NPM.

Create Nx workspace

# Install the Nx workspace generatorpnpm install --global create-nx-workspace# Generate a blank Nx workspacepnpm init nx-workspace my-workspace --preset=empty --pm=pnpm --npm-scope=my-workspace --nx-cloud

Configure Nx workspace

# Install the "json" utilitynpm install --global json# Set the base branch to "main"json -I -f nx.json -e "this.affected.defaultBase = 'main';"

Add Angular capability

# Add Angular capabilitypnpm add --save-dev @nrwl/angular# Initialize Angular workspacenx generate @nrwl/angular:init

Generate Angular app project

# Generate Angular app projectnx generate app my-app

See the video for examples of:

  • Setting up generator defaults
  • Creating a GitHub Actions CI workflow
  • Setting up GitHub workflow triggers
  • Connecting Nx Cloud for distributed computation caching
  • Remove Cypress

Subscribe to our newsletter!

Subscribe to our newsletter to get updates on new content we create, events we have coming up, and more! We'll make sure not to spam you and provide good insights to the content we have.