feat: automatically include env variables starting with NUXT_ENV_ (#3862)

This commit is contained in:
Alexander Lichter 2018-09-08 22:08:25 +01:00 committed by Pooya Parsa
parent f87992530e
commit 1e0219543a
3 changed files with 13 additions and 0 deletions

View File

@ -160,6 +160,10 @@ Options.from = function (_options) {
vueConfig.performance = options.dev
}
// merge custom env with variables
const eligibleEnvVariables = _.pick(process.env, Object.keys(process.env).filter(k => k.startsWith('NUXT_ENV_')))
Object.assign(options.env, eligibleEnvVariables)
// Normalize ignore
options.ignore = options.ignore ? [].concat(options.ignore) : []

View File

@ -1,6 +1,10 @@
import consola from 'consola'
import { buildFixture } from '../../utils/build'
beforeAll(() => {
process.env.NUXT_ENV_FOO = 'manniL'
})
let customCompressionMiddlewareFunctionName
const hooks = [
['render:errorMiddleware', (app) => {
@ -20,3 +24,7 @@ describe('with-config', () => {
expect(customCompressionMiddlewareFunctionName).toBe('damn')
}, hooks)
})
afterAll(() => {
delete process.env.NUXT_ENV_FOO
})

View File

@ -92,6 +92,7 @@ describe('with-config', () => {
expect(html.includes('"string": "ok"')).toBe(true)
expect(html.includes('"num2": 8.23')).toBe(true)
expect(html.includes('"obj": {')).toBe(true)
expect(html).toContain('"NUXT_ENV_FOO": "manniL"')
})
test('/test/error', async () => {