Closed stevebrowndotco closed 7 months ago
@stevebrowndotco thanks for reporting this.
It should indeed copy .env
files to dist
as part of the build step. For example here is one of my projects dist:
A few things to check then:
.env
file in your firebase app project environment
folder?project.json
has the following glob
in its config for assets
? ...
"assets": [
"apps/functions/src/assets",
{
"glob": "**/*",
"input": "apps/firebase/environment",
"output": "."
}
],
....
(assuming your main firebase app project was named firebase
)
Hi @simondotm thank you for checking
@stevebrowndotco
In your first image, .env
file in your environment
folder is greyed by vscode, which normally indicates it is being affected by .gitignore
Please could you check you dont have .env
in your .gitignore
?
This would explain it, since Nx assets copy respects those rules and would not copy .env
in this case.
(The reason why .secret.local
gets copied even though .gitignore
'd is because the plugin adds an exception for this in .nxignore
)
Hi @simondotm many thanks for looking into that. You are correct, it is because it is ignored in git! So I suppose the issue I have is now beyond the scope of this repo but more of an "nx" issue.
This is because I actually have a use case for not wanting .env in source control because of security reasons. I wonder if there is a way to leverage changing the behaviour in the nx config though...
@stevebrowndotco
If your .env
files are intentionally in .gitignore
but you still want to copy them to dist when building, then try adding:
!.env.*
to .nxignore
That should do it.
Hi @simondotm that did it. Thanks for taking a look even though it wasn't strictly an issue with your library
Hi there,
Many thanks for this awesome nx project
I am using version 2.1.2
When I build and deploy my firebase function, the dist/apps/function folder seems to build with .secret.local and .env.local and .env is not there
This seems to be the opposite of what is said here:
https://github.com/simondotm/nx-firebase/blob/main/docs/nx-firebase-functions-environment.md
"The firebase CLI will deploy .env and/or .env. files along with function code, and they can be version controlled. "
and
".env.local and .secret.local files are excluded from deployment by using an functions.ignore rule in firebase.json."
The issue that I have, regardless, is that when I console log process.env.MY_VAR in production, it comes up as
undefined
in google cloud logsIs this a bug or is there something I am doing wrong? The functions block in my firebase.json looks like this (and I have made no changes to this file)