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

feat: envFiles in netlify.toml #4321

Merged
merged 30 commits into from Feb 22, 2022
Merged

feat: envFiles in netlify.toml #4321

merged 30 commits into from Feb 22, 2022

Conversation

iib0011
Copy link
Contributor

@iib0011 iib0011 commented Feb 17, 2022

Summary

Fixes #4272

We can now set a list in netlify.toml in the dev section like this

env_files = [ ".env", ".env.local" ]

We can also set

env_files = [ ]

to avoid any env file being injected

@iib0011 iib0011 requested a review from a team as a code owner February 17, 2022 12:43
@iib0011 iib0011 changed the title 4272 env_priority in netlify.toml and env flag #4272 Feb 17, 2022
@iib0011 iib0011 changed the title env_priority in netlify.toml and env flag #4272 env_priority in netlify.toml and env flag Feb 17, 2022
@erezrokah erezrokah added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Feb 17, 2022
@erezrokah erezrokah changed the title env_priority in netlify.toml and env flag feat: env_priority in netlify.toml and env flag Feb 17, 2022
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Thanks @iib0011, you're on 🔥

I suggest keeping this feature limited to the [dev] block for now, and also name the property envFiles (to match our naming convention) and communicate this is not only about priority, but also which files to use (if any).

Please let me know what you think

site/scripts/docs.mjs Outdated Show resolved Hide resolved
src/utils/init/utils.js Outdated Show resolved Hide resolved
src/utils/dot-env.js Outdated Show resolved Hide resolved
src/commands/dev/dev.js Outdated Show resolved Hide resolved
src/commands/dev/dev.js Outdated Show resolved Hide resolved
@iib0011 iib0011 changed the title feat: env_priority in netlify.toml and env flag feat: env_files in netlify.toml and env flag Feb 17, 2022
@erezrokah
Copy link
Contributor

Thanks for following up with the changes @iib0011, add another comment.
Also do you mind documenting this under https://github.com/netlify/cli/blob/808a54c9900faf144349df1acd21f3884b7e8098/docs/netlify-dev.md#netlifytoml-dev-block and adding a test similar to

test(testName('should pass .env.development vars to function', args), async (t) => {
?

@iib0011 iib0011 changed the title feat: env_files in netlify.toml and env flag feat: env_files in netlify.toml Feb 18, 2022
@iib0011
Copy link
Contributor Author

iib0011 commented Feb 18, 2022

okay

@iib0011
Copy link
Contributor Author

iib0011 commented Feb 18, 2022

@erezrokah should I create a test in each .dev.test file? And can you pls explain to me why there are 8 different test files

@erezrokah
Copy link
Contributor

@erezrokah should I create a test in each .dev.test file? And can you pls explain to me why there are 8 different test files

That's a very good question. You can create a test in the file I linked. See more in #4178 for the reason we have many test files

@iib0011
Copy link
Contributor Author

iib0011 commented Feb 18, 2022

thanks. I just commited the test

@iib0011
Copy link
Contributor Author

iib0011 commented Feb 18, 2022

@erezrokah It is fixed now

@erezrokah
Copy link
Contributor

🚀

@erezrokah erezrokah merged commit 88be608 into netlify:main Feb 22, 2022
@iib0011 iib0011 deleted the envfix branch February 22, 2022 15:16
@erezrokah erezrokah changed the title feat: env_files in netlify.toml feat: envFiles in netlify.toml Feb 22, 2022
@Soviut
Copy link

Soviut commented Feb 22, 2022

@erezrokah @iib0011 Tested and it works well.

https://docs.netlify.com/configure-builds/file-based-configuration/ This will need to be documented here.

@awacode21
Copy link

i was searching on how to load an .env.local with netlify dev. Have nothing found in official documentation. only your report here. So is it usable, or is it future music?

@Soviut
Copy link

Soviut commented May 11, 2022

@awacode21 it's usable since the 9.7.0 release, however, the documentation is lagging behind. As far as I can tell, the docs are not available as a public repo to make PRs to.

Note that the priority is highest to lowest; highest on the left of the array, lowest on the right. So a variable defined in an env file will override any conflicting variables in the files to the right of it in the array.

[dev]
  envFiles = [".env.netlify.local", ".env.netlify"]

@awacode21
Copy link

@Soviut thank you for the detailed explanation and your help :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI flag or config to prevent .env variables being injected
4 participants