Open timwis opened 7 years ago
it basically just does string replacing
Yep, it's literally a find-and-replace. Such is the nature of most transforms haha. Agree that if it isn't clear we should update the docs. PR welcome!
@yoshuawuyts currently the find and replace works if you pass a single var const {VAR_A} = process.env
but not if you pass many, I understand that this is because you use a find and replace for /\bprocess\.env\b/
but there is a way that we can make so it support both.
Babel transpiler converts this:
const {A1, B2} = process.env;
To:
var _process$env = process.env,
A1 = _process$env.A1,
B2 = _process$env.B2
So if we make the regex a bit more generic we can make it match both cases,
e.g. /\b_?process[\.$]env\b/
.
I can send a PR for that if you are ok with this.
It took me about 2 hours of debugging to release this, but when you think about how envify works, it makes sense. I was using object destructuring to cut down on some boilerplate, which works fine in node:
And none of them were being set. So I added a
console.log(process.env)
beneath it, which output{}
, and that made me think envify wasn't being executed at all. Of course it's because envify is parsing the file looking forprocess.env.SOMETHINGHERE
literally.It would be nice if object destructuring were supported, though I can understand why it would be challenging, and accessing
process.env
would almost always be a mistake (except for debugging). Perhaps the solution here is just to make this more clear in the readme, that this module doesn't actually provide aprocess.env
object; it basically just does string replacing?