rsms / figplug

Figma plugin builder
https://rsms.me/figplug/
MIT License
362 stars 16 forks source link

Add rollup-plugin-replace to replace process.env in React builds #3

Closed nguyensomniac closed 5 years ago

nguyensomniac commented 5 years ago

Love using Figplug but always wished the React scaffold would work :( This fixes the error seen in #2, where the imported React library errors out because process is undefined.

I tested this end-to-end with the default React scaffold, and things are working again in Figma!

rsms commented 5 years ago

I just tested this theory (it works) but it’s not ideal. The constant evaluator can’t guarantee that an object property doesn’t change at runtime, so it is unable to eliminate code like this:

if (process.env.NODE_ENV !== "production") {
// lots of helper code
}

Which brings us back to your idea with just replacing strings in the code. I wonder if we can somehow replace this at the AST level instead, so that legitimate text containing the string isn’t replaced...

rsms commented 5 years ago

Okay, I’ve got a good fix for this. Sorry that this PR didn’t land! I really appreciate the time you took to help out :-)