I am deploying a Nuxt App with Zeit/Now. In the development phase I was using a .env
file to store the secrets to my Contentful CMS, exposing the secrets to process.env
with the nuxt-dotenv package. To do that, at the top of the nuxt.config I was calling require('dotenv').config()
.
I then stored the secrets with Zeit/Now and created a now.json to set them up for build and runtime like so:
{
"env": {
"DEMO_ID": "@demo_id"
},
"build": {
"env": {
"DEMO_ID": "@demo_id"
}
}
}
With that setup, the build was only working for the index page and all of the Javascript did not function. Only when I added the env-property to the nuxt.config.js
file, the app started working properly on the Zeit-server.
require('dotenv').config()
export default {
...
env: {
DEMO_ID: process.env.DEMO_ID
},
...
modules: [
'@nuxtjs/dotenv'
],
...
}
BUT: When I then checked the uploaded Javascript files, my secrets were exposed, which I obviously don't want.
What am I doing wrong here? Thanks for your help.