๐ŸŽพ vue-tennis | SSR Migration(Nuxt + Firebase) | 1. Set Environment

protect-meยท2021๋…„ 10์›” 15์ผ
0
post-thumbnail

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) : ํ•˜๋‚˜์˜ ์šด์˜ํ™˜๊ฒฝ์œผ๋กœ๋ถ€ํ„ฐ ๋” ๋‚˜์€ ์šด์˜ํ™˜๊ฒฝ์œผ๋กœ ์˜ฎ์•„๊ฐ€๋Š” ๊ณผ์ •์„ ๋œปํ•˜๋Š” ์ •๋ณดํ†ต์‹  ์šฉ์–ด



๐Ÿงฉ create nuxt project with vuetify


  • $ 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


๐Ÿ”ฅ install firebase


REF : https://firebase.nuxtjs.org/guide/getting-started

  • $ 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


๐Ÿ“ฆ dotenv


์ค‘์š”ํ•œ ํ‚ค๋ฅผ git์— ์˜ฌ๋ฆฌ์ง€ ์•Š๊ณ  ๋ณดํ˜ธํ•˜๊ธฐ ์œ„ํ•œ ์กฐ์น˜

  1. dotenv์— ํ‚ค๋ฅผ ์ด๊ด€
  2. require('dotenv').config()๋ฅผ import
  3. process.env.yourKey๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ
  4. .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 ํ™•์ธ


  • ํ˜„์žฌ๊นŒ์ง€์˜ 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

profile
protect me from what i want

0๊ฐœ์˜ ๋Œ“๊ธ€