From 06ac55485eade945b30991d6b5e1ccd98ea8e94d Mon Sep 17 00:00:00 2001 From: poyoho <907415276@qq.com> Date: Wed, 29 Dec 2021 23:24:54 +0800 Subject: [PATCH 1/6] docs(env-and-mode): add override rule for the env --- docs/guide/env-and-mode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index e764325e1948cf..17da8530d49aa9 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -24,7 +24,7 @@ It will also replace these strings appearing in JavaScript strings and Vue templ ## `.env` Files -Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional environment variables from the following files in your [environment directory](/config/#envdir): +Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional environment variables from the following files in your [environment directory](/config/#envdir) (if define the same variables will override variables in the following order): ``` .env # loaded in all cases From 3b94325a1770fe7cecab01ce4e809b707645a675 Mon Sep 17 00:00:00 2001 From: poyoho <907415276@qq.com> Date: Wed, 29 Dec 2021 23:30:26 +0800 Subject: [PATCH 2/6] fix: docs --- docs/guide/env-and-mode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index 17da8530d49aa9..a1530f432fdad9 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -24,7 +24,7 @@ It will also replace these strings appearing in JavaScript strings and Vue templ ## `.env` Files -Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional environment variables from the following files in your [environment directory](/config/#envdir) (if define the same variables will override variables in the following order): +Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional environment variables from the following files in your [environment directory](/config/#envdir) (if define the same variables will override variables in the following reverse order): ``` .env # loaded in all cases From 04cf8d95e2cdf370803da42f164e2c553372df55 Mon Sep 17 00:00:00 2001 From: poyoho <907415276@qq.com> Date: Fri, 31 Dec 2021 09:49:18 +0800 Subject: [PATCH 3/6] fix: docs with vue-cli --- docs/guide/env-and-mode.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index a1530f432fdad9..3362529ad7e419 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -24,7 +24,7 @@ It will also replace these strings appearing in JavaScript strings and Vue templ ## `.env` Files -Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional environment variables from the following files in your [environment directory](/config/#envdir) (if define the same variables will override variables in the following reverse order): +Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional environment variables from the following files in your [environment directory](/config/#envdir): ``` .env # loaded in all cases @@ -33,6 +33,15 @@ Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional enviro .env.[mode].local # only loaded in specified mode, ignored by git ``` +:::tip Env Loading Priorities + + An env file for a specific mode (e.g. `.env.production`) will take higher priority than a generic one (e.g. `.env`). + + In addition, environment variables that already exist when vite is executed have the highest priority and will not be overwritten by .env files. + + .env files are loaded at the start of vite. Restart the service after making changes. +::: + Loaded env variables are also exposed to your client source code via `import.meta.env`. To prevent accidentally leaking env variables to the client, only variables prefixed with `VITE_` are exposed to your Vite-processed code. e.g. the following file: From 7a862c38ce8fd937d27f0900ba46d065c59312ae Mon Sep 17 00:00:00 2001 From: poyoho <907415276@qq.com> Date: Fri, 31 Dec 2021 09:54:20 +0800 Subject: [PATCH 4/6] chore: format --- docs/guide/env-and-mode.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index 3362529ad7e419..a15e7c5dfeb9f0 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -35,11 +35,11 @@ Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional enviro :::tip Env Loading Priorities - An env file for a specific mode (e.g. `.env.production`) will take higher priority than a generic one (e.g. `.env`). +An env file for a specific mode (e.g. `.env.production`) will take higher priority than a generic one (e.g. `.env`). - In addition, environment variables that already exist when vite is executed have the highest priority and will not be overwritten by .env files. +In addition, environment variables that already exist when vite is executed have the highest priority and will not be overwritten by .env files. - .env files are loaded at the start of vite. Restart the service after making changes. +.env files are loaded at the start of vite. Restart the service after making changes. ::: Loaded env variables are also exposed to your client source code via `import.meta.env`. From 278848b00963b0529d2fe3c17b0029ac3507bd3a Mon Sep 17 00:00:00 2001 From: poyoho <907415276@qq.com> Date: Fri, 31 Dec 2021 12:24:57 +0800 Subject: [PATCH 5/6] chore: beautify Co-authored-by: Bjorn Lu --- docs/guide/env-and-mode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index a15e7c5dfeb9f0..3a5e2ad38bbaa1 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -37,7 +37,7 @@ Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional enviro An env file for a specific mode (e.g. `.env.production`) will take higher priority than a generic one (e.g. `.env`). -In addition, environment variables that already exist when vite is executed have the highest priority and will not be overwritten by .env files. +In addition, environment variables that already exist when Vite is executed have the highest priority and will not be overwritten by `.env` files. .env files are loaded at the start of vite. Restart the service after making changes. ::: From 3c9a79a4e90efd95f6f63022e6e287bc4369d9d2 Mon Sep 17 00:00:00 2001 From: poyoho <907415276@qq.com> Date: Fri, 31 Dec 2021 12:25:12 +0800 Subject: [PATCH 6/6] chore: beautify Co-authored-by: Bjorn Lu --- docs/guide/env-and-mode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index 3a5e2ad38bbaa1..9d6defdf33c778 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -39,7 +39,7 @@ An env file for a specific mode (e.g. `.env.production`) will take higher priori In addition, environment variables that already exist when Vite is executed have the highest priority and will not be overwritten by `.env` files. -.env files are loaded at the start of vite. Restart the service after making changes. +`.env` files are loaded at the start of Vite. Restart the server after making changes. ::: Loaded env variables are also exposed to your client source code via `import.meta.env`.