SSR Migration(Nuxt + Firebase) Series
1. Set Environment ๐๐ป
2. Firebase Usage
CSR : Client Side Rendering
SSR : Server Side Rendering
* CSR์ SPA(Single Page Application)์ ํฌํจํ๋ ๊ฐ๋
๊ธฐ์กด์
CSR
๋ฐฉ์์ผ๋ก ๊ตฌํ๋ ํ๋ก์ ํธ๋ฅผSSR
๋ฐฉ์์ผ๋กMigration
ํ๋ ๊ณผ์ *๋ง์ด๊ทธ๋ ์ด์ (migration) : ํ๋์ ์ด์ํ๊ฒฝ์ผ๋ก๋ถํฐ ๋ ๋์ ์ด์ํ๊ฒฝ์ผ๋ก ์ฎ์๊ฐ๋ ๊ณผ์ ์ ๋ปํ๋ ์ ๋ณดํต์ ์ฉ์ด
$ npx create-nuxt-app yourProjectName
create-nuxt-app v3.7.1
โจ Generating Nuxt.js project in tennis-9-in-nuxt
? Project name: tennis-9-in-nuxt
? Programming language: JavaScript
? Package manager: Npm
? UI framework: Vuetify
? Nuxt.js modules: (Press <space> to select, <a> to toggle all, <i> to invert selectio
n)
? Linting tools: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Testing framework: None
? Rendering mode: Universal (SSR / SSG)
? Deployment target: Server (Node.js hosting)
? Development tools: (Press <space> to select, <a> to toggle all, <i> to invert select
ion)
? What is your GitHub username? yourName
? Version control system: Git
$ npm run serve
localhost:3000
$ npm install firebase
$ npm install @nuxtjs/firebase
firebase > ํ๋ก์ ํธ ์ค์ > ์ผ๋ฐ > ๋ด ์ฑ > SDK ์ค์ ๋ฐ ๊ตฌ์ฑ > ๊ตฌ์ฑ(firebaseConfig ๋ด์ฉ ๋ณต์ฌ)
nuxt.config.js
๋ด์ฉ ์์ modules: ['@nuxtjs/firebase'],
firebase: {
{
config: {
apiKey: '<apiKey>',
authDomain: '<authDomain>',
projectId: '<projectId>',
storageBucket: '<storageBucket>',
messagingSenderId: '<messagingSenderId>',
appId: '<appId>',
measurementId: '<measurementId>'
},
services: {
// Just as example. Can be any other service.
auth: true,
firestore: true,
functions: true,
storage: true,
database: true,
analytics: true,
}
}
}
Error : Cannot read property 'apps' of undefined
- ์์ธ ํ์
$ npm install --save
โnpm WARN @nuxtjs/firebase@7.6.1 requires a peer of firebase@^8.3.1 but none is installed. You must install peer dependencies yourself.
์ฆ,@nuxtjs/firebase@7.6.1
์firebase@^8.3.1
์ ํ์๋ก ํ๋๋ฐ, ์ค์น๋์ด์์ง ์๋ค.- ํด๊ฒฐ
package.json
์์
"firebase": "^9.1.2",
โ"firebase": "^8.3.1",
์์ ํnpm install
์ค์ํ ํค๋ฅผ
git
์ ์ฌ๋ฆฌ์ง ์๊ณ ๋ณดํธํ๊ธฐ ์ํ ์กฐ์น
dotenv
์ ํค๋ฅผ ์ด๊ดrequire('dotenv').config()
๋ฅผ importprocess.env.yourKey
๋ฅผ ํตํด ์ฌ์ฉ.gitignore
์dotenv
์ถ๊ฐ
$ npm install dotenv
$ npm install @nuxtjs/dotenv
root > dotenv
: ๊ธฐ์กด nuxt.config.js
๋ด์ฉ ์ด๊ดVUE_APP_apiKey=<apiKey>
VUE_APP_authDomain=<authDomain>
VUE_APP_projectId=<projectId>
VUE_APP_storageBucket=<storageBucket>
VUE_APP_messagingSenderId=<messagingSenderId>
VUE_APP_appId=<appId>
VUE_APP_measurementId=<measurementId>
nuxt.config.js
์์ require('dotenv').config()
modules: [..., '@nuxtjs/dotenv'],
firebase: {
// REQUIRED: Official config for firebase.initializeApp(config):
config: {
apiKey: process.env.VUE_APP_apiKey,
authDomain: process.env.VUE_APP_authDomain,
databaseURL: process.env.VUE_APP_databaseURL,
projectId: process.env.VUE_APP_projectId,
storageBucket: process.env.VUE_APP_storageBucket,
messagingSenderId: process.env.VUE_APP_messagingSenderId,
appId: process.env.VUE_APP_appId,
measurementId: process.env.VUE_APP_measurementId,
},
.gitignore
๋ด์ฉ ์ถ๊ฐ : .env
package.json
ํ์ธ{
"name": "tennis-9-in-ssr",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {
"@nuxtjs/dotenv": "^1.4.1",
"@nuxtjs/firebase": "^7.6.1",
"core-js": "^3.15.1",
"dotenv": "^10.0.0",
"firebase": "^8.3.1",
"nuxt": "^2.15.7",
"vuetify": "^2.5.5"
},
"devDependencies": {
"@nuxtjs/vuetify": "^1.12.1"
}
}
buildmodules vs modules
buildmodules
์ ๊ฐ๋ฐ ์ค์๋ง ํ์ํ๊ฑฐ๋ ๋น๋๋ฅผ ์คํํ๋ ๋ฐ๋ง ํ์ํ๋ฏ๋ก ํ๋ก๋์ ๋ฒ๋ค์์ ์ ์ธ๋จ
REF : nuxt-firebase-demo