Skip to content

env is being ignored in preset #4539

@foray1010

Description

@foray1010

Babel Configuration (.bablerc, package.json, cli command)

this is my preset config: https://github.com/foray1010/babel-preset-foray1010/blob/d86899e005cde00541251d193c1dce70df316217/react.js

{
  presets: [
    require('babel-preset-es2015'),
    require('babel-preset-stage-2')
  ],
  plugins: [
    require('babel-plugin-transform-decorators-legacy').default,
    [require('babel-plugin-transform-react-jsx'), {
      pragma: 'createElement'
    }]
  ],
  env: {
    production: {
      plugins: [
        require('babel-plugin-transform-react-constant-elements'),
        require('babel-plugin-transform-react-inline-elements'),
        require('babel-plugin-transform-react-remove-prop-types').default
      ]
    },
    test: {
      plugins: [
        require('babel-plugin-istanbul')
      ]
    }
  }
}

this is how I require this preset it in another repo

{
  "presets": [
    "babel-preset-foray1010/react"
  ]
}

I am sure I set correct NODE_ENV to production, I can see process.env.NODE_ENV => production when I console.log in the preset file

Expected Behavior

babel-plugin-transform-react-constant-elements, babel-plugin-transform-react-inline-elements, babel-plugin-transform-react-remove-prop-types should be used

Current Behavior

None of them are being used, but when I put env config into the project .babelrc directly, it works

Context

I want to share my react babel config to all my react project, and there are some plugins that I will only run in production, so I don't want to repeat myself every time in the babelrc on how to handle different env

Your Environment

software version
Babel-core 6.14.0
node 4.5.0
npm 3.10.7
Operating System Ubuntu 16.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRPriority: HighoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions