From 96bd10a60256a62775f83133225d6dd32c7cf4b4 Mon Sep 17 00:00:00 2001 From: Carlos Morales <51803643+cjosue15@users.noreply.github.com> Date: Sun, 6 Nov 2022 07:47:12 -0500 Subject: [PATCH] docs: add note to use dotenv-expand (#10440) (#10798) --- docs/guide/env-and-mode.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index c69badcda5db2e..8c14e9d476fdcb 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -60,6 +60,17 @@ console.log(import.meta.env.VITE_SOME_KEY) // 123 console.log(import.meta.env.DB_PASSWORD) // undefined ``` +Also, Vite uses [dotenv-expand](https://github.com/motdotla/dotenv-expand) to expand variables out of the box. To learn more about the syntax, check out [their docs](https://github.com/motdotla/dotenv-expand#what-rules-does-the-expansion-engine-follow). + +Note that if you want to use `$` inside your environment value, you have to escape it with `\`. + +``` +KEY=123 +NEW_KEY1=test$foo # test +NEW_KEY2=test\$foo # test$foo +NEW_KEY3=test$KEY # test123 +``` + If you want to customize the env variables prefix, see the [envPrefix](/config/shared-options.html#envprefix) option. :::warning SECURITY NOTES