This plugin is almost exactly what I was looking for.
Even though the format of the .env file makes it seem like these are variables in the environment, they are not. The plugin is just parsing that file line by line. Because of this, the plugin will only build when the .env file is present, and is incompatible with actual environment variables.
I'm not exactly sure what changes would be needed to make this work with actual environment variables, but probably something in the project that tells the plugin which variables it needs to look for.