Why not always run the plugin, and then inside the plugin access the environment from the options
object? You can then conditionally run the plugin logic.
If you don’t want to define for which environment it should run within the plugin, you could also do this within serverless.yml
and then have the plugin lookup if it should run or not based on the given environment. Something like
custom:
yourPlugin:
prod:
enabled: true
Indicating that it would only run its logic if the stage equals prod
.