Nuxt忽略的系统环境变量 [英] System environment variables ignored by Nuxt

查看:75
本文介绍了Nuxt忽略的系统环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Nuxt项目使用系统环境变量来设置客户端ID,机密,URL等...

My Nuxt project uses system environment variables to set client ids, secrets, urls, etc...

我的 nuxt.config.js 中有一个示例,其中我使用以下公式设置了几个属性:

An example is in my nuxt.config.js where I set several properties with the following formula:

{
  something: process.env.SOMETHING || 'something_for_dev'
}

Nuxt开发人员版本运行良好,因为它照顾了 process.env.SOMETHING 并正确使用了 something_for_dev .

Nuxt dev version is working fine because looks after the process.env.SOMETHING and correctly use something_for_dev.

Nuxt暂存在Azure上具有其自己的配置,并且 SOMETHING env var已正确设置,但突然它仍然继续使用 something_for_dev ...

Nuxt on staging has its own configuration on Azure and the SOMETHING env var is correctly set but suddenly it still continue using something_for_dev...

我应该怎么做才能让Nuxt使用在服务器上设置的sys env var而不是dev所使用的默认值?谢谢

What should I do to let Nuxt use the sys env vars I set on my Server rather than the default used for dev? Thanks

推荐答案

Env变量设置的是构建时间,而不是运行时.因此,将是在构建期间设置的env变量,好像您在开发计算机上所做的一样.

Env variables are set build time, not runtime. So it will be the env variables that set during your build, which seems you do on your dev machine.

因此,您可以使用适当的env变量进行构建,也可以使用 nuxt-env 模块,允许运行时变量,但请记住,它不允许webpack优化死代码,并且nuxt-env中使用的环境变量是公开的客户端,因此,如果您存储机密,请使用secret config选项

So you can either build with proper env variables or use nuxt-env module, which allows runtime variables, but keep in mind that it wont allow webpack to optimize dead code and environment variables used in nuxt-env are exposed client side, so if you store secrets use the secret config option

这篇关于Nuxt忽略的系统环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆