Permalink
Browse files

fix: handle process.env to have nested keys

  • Loading branch information...
Atinux committed Sep 5, 2017
1 parent 1fcf3e6 commit 20eb5a5eb08334355c745ad8c7f8eef4dc0ac695
@@ -76,7 +76,7 @@ export default function webpackClientConfig () {
// Env object defined in nuxt.config.js
let env = {}
each(this.options.env, (value, key) => {
env['process.env.' + key] = (typeof value === 'string' ? JSON.stringify(value) : value)
env['process.env.' + key] = (['boolean', 'number'].indexOf(typeof value) !== -1 ? value : JSON.stringify(value))
})
// Webpack common plugins
@@ -17,7 +17,7 @@ export default function webpackServerConfig () {
// env object defined in nuxt.config.js
let env = {}
each(this.options.env, (value, key) => {
env['process.env.' + key] = (typeof value === 'string' ? JSON.stringify(value) : value)
env['process.env.' + key] = (['boolean', 'number'].indexOf(typeof value) !== -1 ? value : JSON.stringify(value))
})
config = Object.assign(config, {
@@ -24,7 +24,15 @@ module.exports = {
env: {
bool: true,
num: 23,
string: 'Nuxt.js'
string: 'Nuxt.js',
object: {
bool: true,
string: 'ok',
num2: 8.23,
obj: {
again: true
}
}
},
build: {
// extractCSS: true,
@@ -1,11 +1,20 @@
<template>
<pre>{{ env }}</pre>
<div>
<pre>{{ env }}</pre>
<p>object:</p>
<pre>{{ processEnv }}</pre>
<nuxt-link to="/">Home</nuxt-link>
</div>
</template>
<script>
export default {
layout: 'custom-env',
data() {
return { processEnv: process.env.object }
},
asyncData ({ env }) {
delete env.object
return { env }
}
}
View
@@ -68,6 +68,10 @@ test('/test/env', async t => {
t.true(html.includes('"bool": true'))
t.true(html.includes('"num": 23'))
t.true(html.includes('"string": "Nuxt.js"'))
t.true(html.includes('"bool": false'))
t.true(html.includes('"string": "ok"'))
t.true(html.includes('"num2": 8.23'))
t.true(html.includes('"obj": {'))
})
test('/test/error', async t => {

0 comments on commit 20eb5a5

Please sign in to comment.