Automate deployment of a Vue.js application to Firebase
Fullstack Developer and Tech Author
A quick search online reveals many services available for freely hosting single page applications (SPAs) or static sites. Firebase is one of these services. Firebase is a development platform from Google that provides file storage, hosting, database, authentication, and analytics. It has a no-cost Spark plan, provides an SSL certificate by default, and offers impressive speed across multiple regions.
In this tutorial, I will guide you through using the Firebase CLI to deploy an existing Vue.js application for free. Then we will go beyond manual deployment to set up a continuous deployment (CD) pipeline using CircleCI.
Prerequisites
Make sure that you have the following set up before following along with the tutorial.
You will need:
- Node.js installed. The Vue and Vite tools in this tutorial require Node.js
^22.18.0 || >=24.12.0. - A CircleCI account
- A GitHub account
- Familiarity with building apps with Vue.js
Setting up the demo project
Start by cloning the starter branch of the demo application into a vue-firebase-app folder on your computer. Enter this command:
git clone -b starter https://github.com/CIRCLECI-GWP/vue-firebase-app.git vue-firebase-app
The demo application is a small Vue 3 app scaffolded with create-vue. It uses Vite to serve and build the app, and Vitest to test it.
Change directory into the project. Install all its dependencies and serve the application using:
cd vue-firebase-app
npm install
npm run dev
Go to http://localhost:5173 to review the homepage on your local machine.
Running the unit test locally
Now that the application runs as expected, you need to make sure that the unit tests written for its components are passing. Open a new terminal, and enter this command:
npm run test:unit
Here is the expected output:
> vue-user-app@0.1.0 test:unit
> vitest
DEV v4.1.12 /home/node/vue-firebase-app
✓ tests/unit/user.spec.js (3 tests) 19ms
✓ User List component unit tests: (3)
✓ renders props when passed 9ms
✓ Renders the list 6ms
✓ creates a user 4ms
Test Files 1 passed (1)
Tests 3 passed (3)
Start at 01:05:03
Duration 329ms (transform 30ms, setup 0ms, import 56ms, tests 19ms, environment 204ms)
PASS Waiting for file changes...
press h to show help, press q to quit
Vitest keeps watching your files and reruns the tests when you change one. Press q to stop it.
That is it! Your application is properly set up locally. Your next step is to create a project for the app on Firebase. Later on in the tutorial you will deploy your application using CircleCI and Firebase CLI.
Creating a project on Firebase
Go to the Firebase console. If you don’t have a Firebase account yet, sign in with your Google account to create one.
Adding a project to Firebase
- Click Create a new Firebase project.
- Enter a name for your project, such as
vue-firebase-app. Firebase generates a project ID from the name. Project IDs are unique across Firebase, so yours may differ, and you can’t change it after you create the project. - If prompted, accept the Firebase terms, then click Continue.
- Turn off Enable Gemini in Firebase and click Continue. Then turn off Enable Google Analytics for this project. This project doesn’t need either one.
- Click Create project.
The name step of the dialog looks like this:
You have now successfully created a project on Firebase. Next, you will associate your local project with the Firebase account.
Setting up Firebase hosting
To successfully host your application on Firebase, you need to install its tools and initialize it within your project.
Installing the Firebase CLI
Open a new terminal. To install Firebase tools globally, run this command:
npm install -g firebase-tools
You now have global access to the Firebase Command Line Interface tools. You can use them to deploy code and assets to your newly created Firebase project.
CircleCI needs the Firebase CLI too. From the root of the project, add it as a development dependency:
npm install --save-dev firebase-tools
This adds firebase-tools to package.json and package-lock.json. Commit both files with the rest of the project, so CircleCI installs the same version of the CLI.
Connecting Vue to Firebase
From the terminal, sign in to your Firebase account:
firebase login
Next, go to the root of the vue-firebase-app project. Initialize the project:
firebase init
Here is how to respond to the prompts:
- Choose hosting: Set up deployments for static web apps.
- Use an existing project: Select the Firebase project you created earlier.
- Enter
distas the public directory. That’s the folder Vite writes the production build to. - Configure as a single-page app: Yes.
- Set up automatic builds and deploys with GitHub: No. For this tutorial we are using CircleCI to run tests and handle deployment.
- Install agent skills for Firebase: No. This tutorial doesn’t need them.
The initialization process generates two unique files at the root of your project. These files are required for successful deployment and must be checked into source control:
firebase.jsoncontains your project’s hosting configuration. Its content instructs the Firebase CLI about updating and deploying the files in your project directory..firebasercspecifies the project to connect to the uploaded code once you successfully deploy to Firebase.
It also writes a placeholder dist/index.html. You don’t need to commit it, because npm run build replaces it.
Configuring CircleCI
Next, create a .circleci folder at the root of the project. In it, create a config.yml file with this content:
version: 2.1
jobs:
build-and-test:
working_directory: ~/project
docker:
- image: cimg/node:26.12
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Install Dependencies
command: npm ci
- save_cache:
key: dependency-cache-{{ checksum "package-lock.json" }}
paths:
- ~/.npm
- run:
name: Run test for the application
command: npm run test:unit
- run:
name: Build application for production
command: npm run build
- run:
name: "Generate Service Account Authentication"
command: 'echo "$GOOGLE_APPLICATION_CREDENTIALS_BASE_64" | base64 --decode > $GOOGLE_APPLICATION_CREDENTIALS'
- run:
name: "Deploy app to Firebase Hosting"
command: "npx firebase deploy --non-interactive"
- run:
name: "Remove credentials file"
command: "rm $GOOGLE_APPLICATION_CREDENTIALS"
workflows:
build-and-test:
jobs:
- build-and-test
This configuration specifies all the required tools to install and run the test for your application on CircleCI, and deploys your application to Firebase once the tests are successful.
This script:
- Pulls in the CircleCI Docker image for Node.js
- Uses the image to install all required dependencies, including the Firebase CLI, with
npm ci - Runs the test for your application on CircleCI
- Builds the application for production
- Sets up a command to deploy your application to Firebase when tests are successful
Deployment to Firebase requires authentication from a service account with appropriate privileges on the project. The credentials required for this authentication are provided in a JSON file whose name is saved in the GOOGLE_APPLICATION_CREDENTIALS variable. The Firebase CLI finds the file through this variable, so you don’t need the deprecated --token flag or FIREBASE_TOKEN variable.
To get this JSON file, create a service account that can only deploy to Firebase Hosting:
- In the Google Cloud console, go to the Create service account page and select your Firebase project. It has the same project ID.
- Enter a name for the service account, such as
circleci-firebase-deploy, and click Create and continue. - Grant the service account the Firebase Hosting Admin, API Keys Viewer, and Service Usage Viewer roles, click Continue, and then finish creating the service account.
- On the Service accounts page, click the email address of the new service account and open the Keys tab.
- Click Add key, then Create new key. Select JSON as the key type and click Create. The JSON file downloads to your computer.
NOTE: Firebase Hosting Admin, API Keys Viewer, and Service Usage Viewer are the only roles that the Firebase CLI needs to deploy to Hosting. The CLI uses Service Usage Viewer to check that the Firebase Hosting API is enabled. Avoid using the key of the Firebase Admin SDK service account, which you can generate from the Firebase console. That service account is highly privileged, so using it violates the principle of least privilege. Keep the JSON file private, and delete it from your computer once you’ve added it to CircleCI. If your Google Cloud organization blocks service account key creation, ask an administrator to allow it for this project.
The JSON file you just downloaded will need to be base64 encoded to get the string value of GOOGLE_APPLICATION_CREDENTIALS_BASE_64. On macOS, do this with the following command.
base64 -i path/to/key.json
Replace path/to/key.json with the path to the JSON file you downloaded earlier. On Linux, run base64 -w 0 path/to/key.json instead, so the output is on a single line.
Copy the output of the command and save it somewhere convenient. You will need it later on CircleCI.
When CircleCI is deploying your application to Firebase, the GOOGLE_APPLICATION_CREDENTIALS_BASE_64 variable will be decoded to a file whose name is the value of GOOGLE_APPLICATION_CREDENTIALS. This file will then be used by Firebase to authenticate and deploy the changes.
The next step is to set up a repository on GitHub and link the project to CircleCI. Review Pushing a project to GitHub for instructions.
Log in to your CircleCI account. The steps to set up the project depend on how your CircleCI organization connects to GitHub. The organization’s URL in the CircleCI web app shows which one it uses: /circleci/ for the CircleCI GitHub App, and /github/ or /gh/ for the GitHub OAuth app.
- CircleCI GitHub App: On the Home page, click Create project and follow the prompts. Name the project, set up a pipeline, and choose your repository. If CircleCI prompts you to connect to GitHub, install the CircleCI GitHub App and give it access to the repository. Keep the default All pushes trigger. CircleCI detects the
.circleci/config.ymlfile in the repository. When the project is created, push a commit to start the first pipeline. - GitHub OAuth app: Select Projects in the sidebar and find your repository. Click Set Up Project, choose Fastest to use the
.circleci/config.ymlfile already in the repository, enter the name of your branch, and click Set Up Project. The first pipeline starts right away.
Your first pipeline will fail, as expected, because you haven’t yet created the GOOGLE_APPLICATION_CREDENTIALS_BASE_64 and GOOGLE_APPLICATION_CREDENTIALS environment variables.
To add them, open the Project menu on the project’s pipelines page and select Project settings.
Click Environment Variables in the sidebar, then click Add to create each of these variables:
GOOGLE_APPLICATION_CREDENTIALS_BASE_64is the value of the base64 encoded JSON you generated from the terminal earlier.GOOGLE_APPLICATION_CREDENTIALSis the name of your credentials file, for example,credentials.json. Ensure that whatever name you choose has the .json extension.
Go back to the project’s pipelines page and open the failed pipeline. On the workflow’s row, click the Rerun workflow from failed icon.
Your build should finish successfully.
Go to the Hosting URL shown in the Deploy app to Firebase Hosting step. It has the form https://<your-project-id>.web.app. Firebase also serves your app at https://<your-project-id>.firebaseapp.com, and either address works.
Conclusion
Whether you use Firebase or another hosting service, CircleCI helps you implement continuous integration and continuous deployment (CI/CD) for your Vue.js project. I hope that you found this helpful. The complete source code for this tutorial can be found here on GitHub.