[pre-pull request] --mode switch
See original GitHub issueI didn’t know where to put this and I didn’t want to submit a pull request for unfinished / possibly unwanted additions.
BUT
I forked and added a --mode switch that gets parsed during the ‘getDotenvFilenames’ Fn that should make your module treat .env files the same as vue-cli. (this was more convenient for my team)
Basically if the switch exists it looks for .env.{mode} or .env.{mode}.local files instead of NODE_ENV files, though it will still default to using NODE_ENV as the mode.
function getDotenvFilenames(cwd) {
const { NODE_ENV = 'development' } = process.env;
let modeI = process.argv.indexOf("--mode")
let mode = (modeI != -1 && process.argv.length > modeI + 1) ?
process.argv[modeI + 1] :
NODE_ENV
return [
NODE_ENV && `${cwd}/.env.${mode}.local`,
NODE_ENV && `${cwd}/.env.${mode}`,
NODE_ENV !== 'test' && `${cwd}/.env.local`,
`${cwd}/.env`
].filter(filename => filename && fs.existsSync(filename));
}
If this seems like an addition that would fit I’ll write up some actual testing cases before submitting a pull request.
(if you look in my fork you will also notice that I changed NODE_ENV to default to ‘development’, I don’t plan on including this in a possible pull request.)
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Oh I see. That might be a handy override, and no command line switch needed. I think that’s a much better option then my original proposed change.
Ah. That makes sense. And thanks for the tip on Cammander.js, I hadn’t seen that.
The main reason I decided to keep NODE_ENV and mode separate was because in our use case NODE_ENV is used inside the program to differentiate production vs development or whatever.
And .env files seemed like a good option to start storing those sorts of configurations in a central more manageable location. Though I see now it may have been better to use one or the other and not get stuck between both like I have.
Thank you very much for the input and your work on this tool!
Really it helped a lot!
(edit: spelling)