module.exports = () => {
  const { NODE_ENV, BABEL_ENV } = process.env

  const PRODUCTION = (BABEL_ENV || NODE_ENV) === 'production'

  const browserConfig = {
    useBuiltIns: false,
    targets: {
      browsers: PRODUCTION
        ? ['last 4 versions', 'safari >= 7', 'ie >= 9']
        : ['last 2 versions', 'not ie <= 11', 'not android 4.4.3'],
    },
  }
  return {
    presets: [
      [
        '@babel/preset-env',
        {
          modules: false,
          useBuiltIns: true,
        },
      ],
      '@babel/preset-react',
    ],
    plugins: [
      ['universal-import'],
      [
        '@babel/plugin-transform-runtime',
        {
          helpers: false,
          polyfill: false,
          regenerator: true,
          moduleName: 'babel-runtime',
        },
      ],
      'transform-class-properties',
    ],
    env: {
      development: {
        plugins: ['react-hot-loader/babel'],
      },
      test: {
        presets: ['env', 'stage-0', 'react'],
      },
    },
    compact: false,
  }
}
