똑같은 삽질은 2번 하지 말자
Vue + Firebase + Cloud Functions의 Staging / Production 환경 구축 본문
개요
vue + firebase + cloud functions(API Server) 로 이루어진 어플리케이션의 staging/production 환경 만들기
1. Firebase는 복수의 호스팅이 가능하다.
2. vue-cli를 이용해 staging용 production용 빌드 스크립트 정의
"scripts": {
"build-stg": "vue-cli-service build --mode staging",
"build-prd": "vue-cli-service build --mode production",
// firebase deploy --only hosting:타겟이름(.firebasesrc에 정의한)
"stg-deploy": "npm run build-stg && firebase deploy --only hosting:staging",
"prd-deploy": "npm run build-prd && firebase deploy --only hosting:production",
},
3. Cloud Functions(API Server)의 엔드포인트를 staging용 productuon용으로 나눈다.
# .env.staging
VUE_APP_APIROOT=https://cloudfunctions.net/test-webapi
VUE_APP_ROOT=https://stg-mywebsite.web.app
VUE_APP_MODE=staging
# .env.production
VUE_APP_APIROOT=https://cloudfunctions.net/webapi
VUE_APP_ROOT=https://mywebsite.web.app
VUE_APP_MODE=production
4. vue.config.js의 staging용 production용으로 빌드파일을 분할
const getOutputDir = () => {
if (process.env.VUE_APP_MODE === 'production') {
return 'dist-production'
} else if (process.env.VUE_APP_MODE === 'staging') {
return 'dist-staging'
}
}
module.exports = {
outputDir: getOutputDir(),
,,,
}
5. .firebasesrc 파일의 호스팅 타겟 지정
{
"projects": {
"default": "mywebsite"
},
"targets": {
"mywebsite": {
"hosting": {
"staging": [
"stg-mywebsite"
],
"production": [
"mywebsite"
]
}
}
}
}
6. firebase.json 수정
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"hosting": [
{
"target": "staging",
"public": "dist-staging",
"rewrites": [
...
]
},
{
"target": "production",
"public": "dist-production",
"rewrites": [
...
]
}
],
}
'Vue' 카테고리의 다른 글
Nuxt(SPA) + Firebase 에서 Google Tag Manager를 이용해 page_view 이벤트를 커스텀해보기 (0) | 2022.04.09 |
---|---|
Can I use ... Vue 3? (컨퍼런스 발표 내용) (3) | 2022.02.05 |
[vue-decorator-property] @Prop의 ?: 와 !: 의미 feat. typescript) (0) | 2022.01.27 |
Nuxt에서 Global로 scss의 변수($)나 @mixin을 설정하기 (0) | 2022.01.23 |
Nuxt에서 @nuxjs/dotenv 없이 .env 파일 환경변수 셋팅하기 (0) | 2022.01.09 |
Comments