toddbluhm / env-cmd

Setting environment variables from a file
https://www.npmjs.com/package/env-cmd
MIT License
1.74k stars 65 forks source link

dotenv-expand support? #97

Open bhishp opened 4 years ago

bhishp commented 4 years ago

Is dotenv-expand supported? (https://github.com/motdotla/dotenv-expand)

I think not because I have attempted to add this to the env files but it doesn't work.REACT_APP_APP_VERSION=${npm_package_version}

(as per CRA docs:) https://create-react-app.dev/docs/adding-custom-environment-variables/#expanding-environment-variables-in-env

Happy to raise a PR to add support if someone could point me in the right direction...

toddbluhm commented 4 years ago

Currently dotenv-expand is not supported and probably will never be supported. But the idea of expanding existing env vars is a really cool idea. I will look into implementing that. If you would like to throw together a PR to get this feature implemented sooner, feel free to do so 😄

eckertalex commented 4 years ago

@bhishp I had the same problem and I solved it by using dotenv-cli, which supports dotenv-expand.

You can use it as follows in you package.json:

"start": "dotenv -e .env.staging npm run develop",
steveoh commented 3 years ago

This is different from the existing --expand-envs correct? You have to send the vars in on the CLI or the env variable needs to already exist at run time iiuc?

It would be great to have REACT_APP_APP_VERSION=${npm_package_version} expand. If dotenv-cli can do it, we should be able to add the feature. Has the pr started for this?

Right now I am using an .env-cmdrc.json file with a .env file just for the version expansion. It's not ideal.

nkrul commented 3 years ago

I had a play - for simple expansions only, this should work: https://github.com/toddbluhm/env-cmd/pull/253

motdotla commented 8 months ago

you can use dotenvx for this

HELLO="World"
HELLO2=$HELLO
// index.js
console.log(`Hello ${process.env.HELLO}`)
console.log(`Hello ${process.env.HELLO2}`)
dotenvx run -- node index.js