mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +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
|
||||
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, {
|
||||
|
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: {
|
||||
bool: true,
|
||||
num: 23,
|
||||
string: 'Nuxt.js'
|
||||
string: 'Nuxt.js',
|
||||
object: {
|
||||
bool: true,
|
||||
string: 'ok',
|
||||
num2: 8.23,
|
||||
obj: {
|
||||
again: true
|
||||
}
|
||||
}
|
||||
},
|
||||
build: {
|
||||
// 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>
|
||||
<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 }
|
||||
}
|
||||
}
|
||||
|
@ -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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user