【发布时间】:2020-10-29 22:40:54
【问题描述】:
我在 SPA 模式下使用 Nuxt v2.12.2,并希望在默认 head 中使用环境变量。我正在使用@nuxtjs/dotenv,但是当页面呈现时,baseUrl 是未定义的。
.env
BASE_URL=https://example.com
nuxt.config.js
require('dotenv').config()
export default {
mode: 'spa',
generate: {
fallback: true
},
env: {
baseUrl: process.env.BASE_URL || 'http://localhost:3000'
},
head: {
meta: [
{
hid: 'og:image',
name: 'og:image',
content: process.env.baseUrl + '/og/facebook.png'
}
],
},
modules: [
'@nuxtjs/dotenv'
]
...
}
【问题讨论】: