Angular Universal Server Side Rendering (SSR) allows you to render your Angular application on the server before sending it to the browser, which can greatly improve performance and SEO. In this tutorial, we will walk you through the process of deploying an Angular SSR application to Netlify in just a few simple steps, and setting up continuous integration/continuous deployment (CI/CD) using GitHub.
Prerequisites:
- An Angular project with SSR enabled.
- A GitHub account.
- A Netlify account.
Step 1: Set up your Angular project for SSR
If you haven’t already enabled SSR in your Angular project, you can do so by following the official Angular Universal guide (https://angular.io/guide/universal). Once SSR is enabled, build your project using the following command:
ng build --prod
Step 2: Create a new GitHub repository
Create a new repository on GitHub to host your Angular project. Push your code to the repository using the following commands:
git init
git add .
git commit -m "Initial commit"
git remote add origin <repository_url>
git push -u origin master
Step 3: Set up CI/CD with GitHub Actions
Create a new file called deploy.yml
in the .github/workflows
directory of your project and add the following code:
name: Deploy
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Build project
run: ng build --prod
This GitHub Actions workflow will run every time you push code to the master
branch, building the project using the ng build --prod
command.
Step 4: Deploy your Angular SSR application to Netlify
Sign in to Netlify and click on the "New site from Git" button. Select GitHub as your Git provider, choose the repository where your Angular project is hosted, and configure the build settings:
- Build command:
npm run build:ssr
- Publish directory:
dist/your-project-name/browser
Click "Deploy site" to deploy your Angular SSR application to Netlify.
Step 5: Set up environment variables
If your Angular project relies on environment variables, you can set them up in the Netlify dashboard under "Site settings" > "Build & deploy" > "Environment". Add your environment variables and save the changes.
That’s it! Your Angular SSR application is now deployed to Netlify, and any new changes you push to the master
branch on GitHub will trigger a new build and deployment automatically. This CI/CD pipeline ensures that your application is always up-to-date and running smoothly.
In conclusion, deploying an Angular SSR application to Netlify in just a few simple steps and setting up CI/CD with GitHub is a powerful way to streamline your development workflow and ensure a seamless deployment process. With server-side rendering and continuous integration in place, your Angular application will be fast, SEO-friendly, and always up-to-date.
What if I want to depoly the whole dist/<app-name> folder and want to run server/server.mjs file?
How Angular 17 render multiple routes using SSR?
Thank you Esther for the tutorial. I got a challenge when deploying my angular app to github pages. Only the index page loads on the browser. seems github pages does not support angular routing. Am thinking it could be the same thing with Netlify. Do u think Netlify supports angular routing for a site having multiple pages (navbar options)?
Excellent!
Great job, well done!
Nextjs routing system is batter then angular