chihab / dotenv-run

Seamlessly load environment variables. Supports cli, esbuild, rollup, vite, webpack, angular. ESM and Monorepos.
238 stars 17 forks source link

how to apply Env Vars to multiple npm scripts #80

Closed xmlking closed 6 months ago

xmlking commented 6 months ago

Recently I needed to run two scripts svelte-kit sync & vite dev and pass Env Vars to second command.

This works

"scripts": {
   "dev": "dotenv-run -v -f .env -f .secrets -- vite dev"
}

This didn't work. Env Vars are not passed to vite dev command

"scripts": {
   "dev": "dotenv-run -v -f .env -f .secrets -- svelte-kit sync && vite dev"
}

any recommendations to accomplish this?

chihab commented 6 months ago

dotenv-run -v -f .env -f .secrets -- bash -c 'svelte-kit sync && vite dev'?

or have a npm script:

"scripts": {
   "dev:run": "svelte-kit sync && vite dev",
   "dev": "dotenv-run -v -f .env -f .secrets -- npm run dev:run"
}
xmlking commented 6 months ago

Second one should work for both windows and Mac b.t.w -f .env,.secrets did not work on windows. Have to rewrite -f .env -f .secrets

chihab commented 6 months ago

I'll close the issue, let me know if you need any help.