Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

.env loader #15

Open
Faithfinder opened this issue May 12, 2022 · 1 comment
Open

.env loader #15

Faithfinder opened this issue May 12, 2022 · 1 comment

Comments

@Faithfinder
Copy link
Contributor

Our repo has a bunch of apps, but they all talk to the same database. Would be cool if we could specify the db url in a centralized manner, with a topmost .env file, rather than in every project separately.

Seems like a perfect usecase for a plugin - "Before every rush command, use dotenv". Ideally it would also work on rushx, though I don't remember if it's currently possible to plug in to rushx behaviour.

@chengcyber
Copy link
Collaborator

chengcyber commented May 18, 2022

Thoughts:

  1. "Before every rush command, use dotenv".

Technically yes. You can do it by rush plugin right now but only for rush commands.

ideally it would also work on rushx

Nope. rushx is treated as pnpx. I don't believe pnpx is the right CLI to plugin things.

  1. I am not 100% sure it's helpful if you can inject .env files for all commands. Since connecting to database seems to be a very specified behavior of a command in each project rather than the management in whole repo. If so, your point is mainly about reusablity in Monorepo, and the solution in RushStack world is rig package. IMHO, .env in your case is another configuration can be included in a rig, and loading .env for the specified command.

The workflow would be like:

  1. Create a sibling rig package in your monorepo to manage .env file and provide a env-loader js file.
  2. Make project A depends on this rig package.
  3. Loading .env in each project, use webpack as an example:
// webpack.config.js

require('<rig_package_name>/env-loader.js')

module.exports = {}

Moreover, webpack.config.js is another riggable file, you can manage your .env files beside your webpack config files now!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants