heroku中的环境变量

时间:2017-10-13 15:06:45

标签: javascript reactjs heroku production

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配置文件。

在我的proc文件中我有:web: NODE_ENV=production node ./src/server/index.js

在我的网站中我有:

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

1 个答案:

答案 0 :(得分:0)

不确定是否有任何问题可以解决您的问题,但希望它有所帮助。

1)在没有“NODE_ENV = production”的Procfile之前,Heroku能否拿起“开始”脚本?我不使用Procfile,我只依赖启动脚本,所以不确定。

2)NODE_ENV =生产肯定是在&&&在开始:生产脚本调用?在节点脚本之前复制并粘贴它也是值得的,只是为了确定。

3)JSON.stringify将空字符串解析为true,因此最好放置|| JSON.stringify函数中的“development”,如下所示:

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

4)你在“开发”周围有单引号和双引号,它会创建带双引号的字符串,这个字符串只是单词开发的字符串。

相关问题