kentcdodds / babel-plugin-macros

🎣 Allows you to build simple compile-time libraries
https://npm.im/babel-plugin-macros
MIT License
2.62k stars 135 forks source link

read environment specific config #108

Closed codepunkt closed 5 years ago

codepunkt commented 5 years ago

It would be great if babel-plugin-macros could read environment specific configuration the way babel does, e.g. using styled-components macro with this configuration in package.json would then use { displayName: true} unless in production, where it would use { displayName: true }

{
  "babelMacros": {
    "styledComponents": {
      "displayName": true,
      "env": {
        "production": {
          "displayName": false
        }
      }
    }
  }
}

What do you think?

kentcdodds commented 5 years ago

Hi @codepunkt!

I never liked that feature in babel's config because I always found it confusing. Instead, I recommend folks use the js variant.

// babel-plugin-macros.config.js
module.exports = {
  styledComponents: {
    displayName: process.env.NODE_ENV !== 'production'
  }
}

I much prefer this in my own babel config and I don't want to create a DSL for something so simple. Thanks anyway!

codepunkt commented 5 years ago

@kentcdodds thanks! 👍