I've created a Next.js project with nx g @nrwl/next:app myapp.
When running nx serve myapp, I want to be able to load environment variables from a .env file in my application project folder. e.g. myworkspace/apps/myapp/.env.
As an additional feature, I'd like to be able to pass the name of the environment file as a builder option. This will allow a developer to specify different environment variables for each configuration.
e.g.
nx serve myapp --configuration=development could load myworkspace/apps/myapp/development.env.nx serve myapp --configuration=production could load myworkspace/apps/myapp/production.env.Upon running nx serve myapp, environment variables are loaded only from the root of the workspace: myworkspace/.env.
@nrwl/[email protected]
@nrwl/[email protected]
Environment variables typically differ for each application in a monorepo, so it makes more sense to define them per-project rather than a global .env for the workspace.
@elliottsj there is a feature/issue request for that https://github.com/nrwl/nx/issues/1848 and a PR https://github.com/nrwl/nx/issues/1848 but still waiting on the maintainers to reply on the PR.
@weblancaster Thanks, though I believe that this is slightly different than the proposed build-time environment variables.
I am proposing that we change the existing dotenv code which loads environment variables from a .env file, so that it's more customizable, allowing us to specify a specific file to load env vars from.
Most helpful comment
@weblancaster Thanks, though I believe that this is slightly different than the proposed build-time environment variables.
I am proposing that we change the existing dotenv code which loads environment variables from a
.envfile, so that it's more customizable, allowing us to specify a specific file to load env vars from.