$ npm i --save @nuxtjs/dotenv
$ yarn add @nuxtjs/dotenv
nuxt.config.js
plugins: [
'~/plugins/firebase.js',
],
modules: [
'@nuxtjs/dotenv',
],
plugins/firebase.js
import firebase from "firebase/app";
import "firebase/auth";
if (!firebase.apps.length) {
firebase.initializeApp({
apiKey: process.env.API_KEY,
authDomain: process.env.AUTH_DOMAIN,
databaseURL: process.env.DATABASE_URL,
projectId: process.env.PROJECT_ID,
storageBucket: process.env.STORAGE_BUCKET,
messagingSenderId: process.env.MESSAGING_SENDER_ID,
appId: process.env.APP_ID
})
}
export default firebase;
.envファイル
.env
API_KEY='AIXXXXXXXXXXXXXXXXXXXXXXXX'
AUTH_DOMAIN='hogefuga.firebaseapp.com'
DATABASE_URL='https://hogefuga.firebaseio.com'
PROJECT_ID='hogefugao'
STORAGE_BUCKET='hogefuga.appspot.com'
MESSAGING_SENDER_ID='123456789'
APP_ID='1:123456789:web:abcde1234'