Adding array of values in env
My extension will run on several sites e.g. amazon, ebay, alibaba. Each site has some specific configurations like the website domain and the specific div classes that I use to locate products on the site. Currently I have these configurations in their own .env.amazon, .env.ebay, .env.alibaba and create a build for each ...
But we now want one build that will work on all three sites and any site we may add in the future (we'll be adding sites often). To my understanding, env files only take string values so my only option is to concatenate all the values into a pipe-separated string like so
And then modify my existing code to parse the values
Is this the only option? I'm worried about having one giant string bc
1. maintenance/readability - we'll be adding a lot of customers soon
2. collisions of div classes, for instance if ".product-image" is the appropriate class for amazon but also exists in ebay it could mess things up
I would like to keep them visually separated like in the env above if possible. I'm sure there are JSON based env-type files but does Plasmo work with those? I definitely want to keep the configuration in a separate file (not hardcoded) so that if we sign another customer onboarding them is as easy as adding to the config file
Thanks!
22 Replies
@Pallas
check out https://github.com/PlasmoHQ/plasmo/pull/757 .. it's in 0.83.0 .. you can use this in any context that
"$WHATEVER"
vars are processed by plasmo (like in a content script config)GitHub
feat: Introduces JSON type to non-public env variables by sleekslus...
Details
Note: I'm open to conversation on this idea, so please let me know your thoughts and whether something like this would be useful. Also, would be curious to know if any alternative solut...
Thanks @filthytone , it's not working for me. It's being read as-is, you can see the "json([ ... " wrapper. I checked that I'm in 0.83.0.
Here's my .env.development. Anything I'm doing wrong?
`
![No description](https://cdn.answeroverflow.com/1154566531494199406/Screenshot_2023-09-21_at_4.49.53_PM.png)
Gave +1 Rep to @filthytone
@hgil has reached level 4. GG!
Don’t use the plasmo_public prefix
Ah. Ok wasn't sure what was meant by non-public in the Github Issue. Thx let me try!
Works! Thx @filthytone . One note though, I directly copied the example from the Github Issue which had its own square brackets [], so at compilation I got an error "expected string" (instead it got another list []). I removed the brackets and all good.
Should i have based it off some documentation?
![No description](https://cdn.answeroverflow.com/1154569378361258034/Screenshot_2023-09-21_at_5.04.02_PM.png)
Gave +1 Rep to @filthytone
Yea has to be a string value so removing brackets was correct
The final result will be an array as you see
None of this is documented .. I had the exact same need but in a manifest context , so I implemented it
There’s technically a typescript error on the config object, but that easily fixed too
Oh you're sleekslush! Sweet man thanks a ton for implementing!!
Gave +1 Rep to @filthytone
Yeah figured about the documentation just wondering
no problem! and yea, lol same guy
you can fix the typescript error like this
and then rejoice w/ the typescript gods
Ok took me a bit to figure out but first I celebrated early when I said it worked. I actually had an empty list in matches. The fix was the code you just shared (I thought you meant there was a benign error). But in that code I I had to then add back the square brackets because previously i had
So now my .env matches what you had in the Github Issue
So now one more question for you before I spend too much time trying to get this to work:
I also need this to dynamically set class names in my getOverlayAnchorList()
Is that possible? Idk if I need to use process.env in that case
@filthytone also what about in a content.css lol
Hm actually just realized I need a map