1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-universal-configuration-build-time/next.config.js
Fredrik Höglund 2ab1ae7f61 Updated examples for build-time env configuration for v8 (#6237)
* Updated examples for build-time env configuration for v8

* Add comment to build time config example with how to include entire .env
2019-02-11 14:15:06 +01:00

46 lines
1.2 KiB
JavaScript

const dotEnvResult = require('dotenv').config()
const prod = process.env.NODE_ENV === 'production'
if (dotEnvResult.error) {
throw dotEnvResult.error
}
module.exports = {
env: {
TEST: process.env.TEST,
BACKEND_URL: prod ? 'https://api.example.com' : 'https://localhost:8080'
}
}
/*
If you want to include every variable in .env automatically,
replace the above module.exports with the code below.
Warning: The below technique can be dangerous since it exposes every
variable in .env to the client. Even if you do not currently have
sensitive information there, it can be easy to forget about this when
you add variables in the future.
If you have many variables and want a safer way to conveniently expose
them, see the example "with-dotenv".
*/
/*
const parsedVariables = dotEnvResult.parsed || {}
const dotEnvVariables = {}
// We always want to use the values from process.env, since dotenv
// has already resolved these correctly in case of overrides
for (const key of Object.keys(parsedVariables)) {
dotEnvVariables[key] = process.env[key]
}
module.exports = {
env: {
...dotEnvVariables,
BACKEND_URL: prod ? 'https://api.example.com' : 'https://localhost:8080'
}
}
*/