🧩 Plasmo Developers�PD
🧩 Plasmo Developers3y ago
37 replies
hgil

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 ...

// AMAZON
PLASMO_PUBLIC_SHOPADVISOR_CUSTOMER_PRODUCT_PAGE="amazon.co/*/dp/*"
PLASMO_PUBLIC_SHOPADVISOR_ANCHOR_CLASSES=".s-product-image-container, .a-dynamic-image, .product-image, .a-image-container, .a-dynamic-image-container"

// EBAY
PLASMO_PUBLIC_SHOPADVISOR_CUSTOMER_PRODUCT_PAGE="ebay.co/listing/*"
PLASMO_PUBLIC_SHOPADVISOR_ANCHOR_CLASSES=".ebay-product-grid__image-container .featured-product"

// ALIBABA


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

PLASMO_PUBLIC_SHOPADVISOR_CUSTOMER_DOMAIN="amazon.co/* | "ebay.co/*"| "alibaba.co/*""


And then modify my existing code to parse the values

export const config: PlasmoCSConfig = {
  // TODO: Parse from pipe-delimited string
  matches: ["$PLASMO_PUBLIC_SHOPADVISOR_CUSTOMER_PRODUCT_PAGE"]
}


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!
Was this page helpful?