2017-10-13 87 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)你身边有单,双引号“‘发展’”这将创建一个双引号括起来的这将是一个不同的字符串只是发展这个词。