2017-10-13 89 views
1
const firebase = require('firebase'); 
const devConfig = { 
//config here 
}; 
const prodConfig = { 
//config here 
}; 

export const firebaseInit = firebase.initializeApp(process.env.NODE_ENV == 'development' ? devConfig : prodConfig); 
export const rootRef = firebase.database().ref(); 

我有這個firebase配置文件。環境變量in heroku

我procfile

我有:web: NODE_ENV=production node ./src/server/index.js

在我的WebPack

我有:

plugins: [ 
    new webpack.DefinePlugin({ 
     'process.env': { 
      'NODE_ENV': JSON.stringify(process.env.NODE_ENV) || '"development"' 
     } 
    }), 

,並在我的package.json我有:

"start": "node src/server/index.js", 
"start:production": "NODE_ENV=production ./node_modules/.bin/webpack && node src/server/index.js", 
"start:dev": "NODE_ENV=development ./node_modules/.bin/webpack && node src/server/index.js", 

,並在我的Heroku應用程序設置我已將NODE_ENV設置爲production作爲值

我已經部署了主代碼後推我的代碼。但是當應用程序啓動時,它仍以我的控制檯登錄爲「開發模式」。我錯過了什麼在生產中啓動應用程序?我可以做到這一點本地只是不heroku

+0

https://devcenter.heroku.com/articles/config-vars –

+0

@Mark_M我已經完成了上述操作 –

+0

我看不到你在哪裏調用類似'heroku config:set NPM_CONFIG_PRODUCTION = production' –

回答

0

不知道這是否有任何修復您的問題,但希望它可以幫助。

1)Heroku是否可以在沒有「NODE_ENV = production」的Procfile之前拾取「start」腳本?我不使用Procfile,我只是依賴啓動腳本,所以不確定。

2)NODE_ENV =生產肯定是在& &之後開始:生產腳本調用?值得肯定的是,它可能值得複製並粘貼到節點腳本之前。

3)JSON.stringify會將空字符串解析爲真,因此最好將|| 「發展」的JSON.stringify函數內部,就像這樣:

'NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development') 

4)你身邊有單,雙引號「‘發展’」這將創建一個雙引號括起來的這將是一個不同的字符串只是發展這個詞。