Webpack: using an .env file

Created on 22 Dec 2017  Â·  3Comments  Â·  Source: vuejs-templates/webpack

Hi,

I have added a .env file to pull in my firebase API key (FIREBASE_KEY) to the root of my project but I cannot get the variable out using process.env.FIREBASE_KEY. how do I go about doing this?

question

Most helpful comment

I'm actually working on a bigger PR to support this properly across all features / modes of this template in #1178

chiayutsaipersonal has already mentioned the important part - using dotenv, I just want to make clear that this only gets you the API key into the node process that's running (i.e. webpack), not into your app.

So to get it into your app, you would have to add it to /config/dev.env.js:

require('dotenv').config()

module.exports = {
  NODE_ENV: '"development"',
  FIREBASE_KEY: JSON.stringify(process.env.FIRBASE_KEY)
}

All 3 comments

const dotenv = require('dotenv')

dotenv.config() // before process.env.FIREBASE_KEY is accessed

I'm actually working on a bigger PR to support this properly across all features / modes of this template in #1178

chiayutsaipersonal has already mentioned the important part - using dotenv, I just want to make clear that this only gets you the API key into the node process that's running (i.e. webpack), not into your app.

So to get it into your app, you would have to add it to /config/dev.env.js:

require('dotenv').config()

module.exports = {
  NODE_ENV: '"development"',
  FIREBASE_KEY: JSON.stringify(process.env.FIRBASE_KEY)
}

Awesome thanks. Yes that last part is the bit I was missing to pass the param through.

Kind regards,

Simon Smale

On 27 Dec 2017, at 09:56, Thorsten Lünborg notifications@github.com wrote:

I'm actually working on a bigger PR to support this properly across all features / modes of this template in #1178

hiayutsaipersonal has already gotten th important part - using dotenv, I just want to make clear that this only gets you the API key into the node process that's running (ie.e webpack), not into your app.

So to get it into your app, you would have to add it to /config/dev,ev.js:

require('dotenv').config()

module.exports = {
NODE_ENV: '"development"',
FIREBASE_KEY: JSON.stringify(process.env.FIRBASE_KEY)
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Was this page helpful?
0 / 5 - 0 ratings