Skip to content

Commit

Permalink
feat: automatically include env variables starting with NUXT_ENV_ (nu…
Browse files Browse the repository at this point in the history
  • Loading branch information
manniL authored and pi0 committed Sep 8, 2018
1 parent f879925 commit 1e02195
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/common/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) : []

Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/with-config/with-config.test.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -20,3 +24,7 @@ describe('with-config', () => {
expect(customCompressionMiddlewareFunctionName).toBe('damn')
}, hooks)
})

afterAll(() => {
delete process.env.NUXT_ENV_FOO
})
1 change: 1 addition & 0 deletions test/unit/with-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 1e02195

Please sign in to comment.