Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(env-and-mode): add override rule for the env #6304

Merged
merged 6 commits into from Dec 31, 2021

Conversation

poyoho
Copy link
Member

@poyoho poyoho commented Dec 29, 2021

Description

#6302

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@Niputi Niputi linked an issue Dec 30, 2021 that may be closed by this pull request
7 tasks
@@ -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 reverse order):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it reads hard 🤔
Maybe better something like this? Could even be written better.

Suggested change
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) (if they define the same variable, the variable defined in the most specific file will win):

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think .env.${mode}.local is in the most specific, but it will be overwrite 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in not the most specific will win?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the most specific currently don't win, then IMO this is a bug and should be changed
And I assume this is what #6306 is fixing 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check https://cli.vuejs.org/guide/mode-and-env.html#environment-variables, see green alert with title Env Loading Priorities

@Niputi Niputi added the documentation Improvements or additions to documentation label Dec 30, 2021
@bluwy bluwy mentioned this pull request Dec 30, 2021
9 tasks
@poyoho poyoho requested a review from userquin December 31, 2021 01:49
@userquin
Copy link
Contributor

userquin commented Dec 31, 2021

this should be in sync with #6303 , I don't know if the last paragraph added is required, I don't know all vite internals (about restarting)...

@poyoho
Copy link
Member Author

poyoho commented Dec 31, 2021

I test it. It need to restart.

@poyoho poyoho requested a review from userquin December 31, 2021 02:15
userquin
userquin previously approved these changes Dec 31, 2021
docs/guide/env-and-mode.md Outdated Show resolved Hide resolved
docs/guide/env-and-mode.md Outdated Show resolved Hide resolved
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
@patak-dev patak-dev merged commit d8502e2 into vitejs:main Dec 31, 2021
@poyoho poyoho deleted the docs/env-and-mode branch April 26, 2022 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import.meta.env.MODE=production while import.meta.env.PROD returned false
6 participants