mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-06 21:10:38 +00:00
fix: handle process.env to have nested keys
This commit is contained in:
parent
1fcf3e685e
commit
20eb5a5eb0
@ -76,7 +76,7 @@ export default function webpackClientConfig () {
|
|||||||
// Env object defined in nuxt.config.js
|
// Env object defined in nuxt.config.js
|
||||||
let env = {}
|
let env = {}
|
||||||
each(this.options.env, (value, key) => {
|
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
|
// Webpack common plugins
|
||||||
|
@ -17,7 +17,7 @@ export default function webpackServerConfig () {
|
|||||||
// env object defined in nuxt.config.js
|
// env object defined in nuxt.config.js
|
||||||
let env = {}
|
let env = {}
|
||||||
each(this.options.env, (value, key) => {
|
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, {
|
config = Object.assign(config, {
|
||||||
|
10
test/fixtures/with-config/nuxt.config.js
vendored
10
test/fixtures/with-config/nuxt.config.js
vendored
@ -24,7 +24,15 @@ module.exports = {
|
|||||||
env: {
|
env: {
|
||||||
bool: true,
|
bool: true,
|
||||||
num: 23,
|
num: 23,
|
||||||
string: 'Nuxt.js'
|
string: 'Nuxt.js',
|
||||||
|
object: {
|
||||||
|
bool: true,
|
||||||
|
string: 'ok',
|
||||||
|
num2: 8.23,
|
||||||
|
obj: {
|
||||||
|
again: true
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
// extractCSS: true,
|
// extractCSS: true,
|
||||||
|
11
test/fixtures/with-config/pages/env.vue
vendored
11
test/fixtures/with-config/pages/env.vue
vendored
@ -1,11 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<pre>{{ env }}</pre>
|
<div>
|
||||||
|
<pre>{{ env }}</pre>
|
||||||
|
<p>object:</p>
|
||||||
|
<pre>{{ processEnv }}</pre>
|
||||||
|
<nuxt-link to="/">Home</nuxt-link>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
layout: 'custom-env',
|
layout: 'custom-env',
|
||||||
|
data() {
|
||||||
|
return { processEnv: process.env.object }
|
||||||
|
},
|
||||||
asyncData ({ env }) {
|
asyncData ({ env }) {
|
||||||
|
delete env.object
|
||||||
return { env }
|
return { env }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,10 @@ test('/test/env', async t => {
|
|||||||
t.true(html.includes('"bool": true'))
|
t.true(html.includes('"bool": true'))
|
||||||
t.true(html.includes('"num": 23'))
|
t.true(html.includes('"num": 23'))
|
||||||
t.true(html.includes('"string": "Nuxt.js"'))
|
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 => {
|
test('/test/error', async t => {
|
||||||
|
Loading…
Reference in New Issue
Block a user