In this tutorial, we are going to deploy our Vue application to the firebase server for different environments.
Before putting any project into production it needs to develop, QA first.
So, for different cases, we may need different configurations and need to use different server resources.
According to this requirement, we need to set up different configuration files for different environments. So while deploying, it can take a specific config for the corresponding environment.
Generally, what we are going to do is:
- Create different projects for different env in firebase
- Set up firebase hosting in our application
- Configuring test config file for different environment
- Deploy the application for different environment
npm install -g firebase-tools
For yarn package manager:
yarn global add firebase-tools
firebase login
This will redirect you to login with a Google account. Use the same account to login which is used to create for the different firebase projects previously.
firebase init
{
"projects": {
"default": "develop-vue-test"
}
}
As we use default firebase project as "develop-vue-test" while doing firebase init.{
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
This is the firebase config file where you can see the setup we did previously. For e.g "public": "dist" as we choose dist as public.VUE_APP_ENDPOINT=https://develop.com
You can create whatever config key-value pair here with the respective environment. We are using VUE_APP_ENDPOINT test sample.VUE_APP_ENDPOINT=https://qa.com
You can access that config file property anywhere by using:
process.env.VUE_APP_ENDPOINT
{
"projects": {
"default": "develop-vue-test",
"qa": "qa-vue-test"
}
}
Let's go to the package.json file and add and change the build script to use this config file.
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"develop": "vue-cli-service build --mode develop",
"qa": "vue-cli-service build --mode qa"
},
Here, we added two more scripts for develop and qa environment.yarn develop
Which will build the application for develop env.
firebase deploy
as inside the firebase.json file, the default project is selected as develop-vue-test so it will simply deploy to develop.
yarn qa
firebase deploy -P qa
Make sure the name "qa" needs to same as the name of the project defined in firebase.json. This will simply deploy the build folder to "qa-vue-test" firebase project.