// @flow

// most of this has been inspired by
// https://github.com/facebook/create-react-app/tree/master/packages/babel-preset-react-app

module.exports = () => ({
  presets: [
    [
      require("@babel/preset-env"),
      {
        ...(process.env.PHENOMIC_ENV === "static"
          ? {
              targets: {
                node: "current",
              },
            }
          : {
              // Do not transform modules to CJS since bundler like webpack handle it
              modules: false,
            }),
        // If users import all core-js they're probably not concerned with
        // bundle size. We shouldn't rely on magic to try and shrink it.
        useBuiltIns: false,
        // Exclude transforms that make all code slower
        exclude: ["transform-typeof-symbol"],
      },
    ],
    [
      require("@babel/preset-react"),
      {
        // Adds component stack to warning messages
        // Adds __self attribute to JSX which React will use for some warnings
        development: process.env.PHENOMIC_ENV !== "static",
        // Will use the native built-in instead of trying to polyfill
        // behavior for any plugins that require one.
        useBuiltIns: true,
      },
    ],
    require("@babel/preset-flow"),
  ],
  plugins: [
    // Enable loose mode to use assignment instead of defineProperty
    // See discussion in https://github.com/facebook/create-react-app/issues/4263
    [
      require("@babel/plugin-proposal-class-properties"),
      {
        loose: true,
      },
    ],
    // The following two plugins use Object.assign directly, instead of Babel's
    // extends helper. Note that this assumes `Object.assign` is available.
    // { ...todo, completed: true }
    [
      require("@babel/plugin-proposal-object-rest-spread"),
      {
        useBuiltIns: true,
      },
    ],
    // Polyfills the runtime needed for async/await, generators, and friends
    // https://babeljs.io/docs/en/babel-plugin-transform-runtime
    [
      require("@babel/plugin-transform-runtime").default,
      {
        corejs: false,
        helpers: false,
        regenerator: true,
        useESModules: process.env.PHENOMIC_ENV === "static",
      },
    ],
    process.env.NODE_ENV === "production" && [
      // Remove PropTypes from production build
      require("babel-plugin-transform-react-remove-prop-types").default,
      {
        removeImport: true,
      },
    ],
    // Adds syntax support for import()
    require("@babel/plugin-syntax-dynamic-import"),
    // Transform dynamic import to require
    process.env.PHENOMIC_ENV === "static" &&
      require("babel-plugin-dynamic-import-node"),
  ],
});

@@ -2043,26 +2043,18 @@
 untime%22)
-.default
 ,%0A
+
       %7B%0A
@@ -2204,24 +2204,28 @@
 %0A    %5D,%0A    
+...(
 process.env.
@@ -2253,14 +2253,37 @@
 ion%22
- && %5B%0A
+%0A      ? %5B%0A          %5B%0A      
     
@@ -2326,16 +2326,22 @@
 n build%0A
+      
       re
@@ -2399,24 +2399,16 @@
 es%22)
-.default
 ,%0A      
 %7B%0A  
@@ -2395,34 +2395,46 @@
 -types%22),%0A      
+ 
-%7B%0A
+     %7B%0A      
         removeIm
@@ -2447,32 +2447,67 @@
 true,%0A      
-%7D,%0A    %5D
+      %7D,%0A          %5D,%0A        %5D%0A      : %5B%5D)
 ,%0A    // Add
@@ -2635,16 +2635,20 @@
 ire%0A    
+...(
 process.
@@ -2680,18 +2680,18 @@
 tic%22
- &&
 %0A      
+? %5B
 requ
@@ -2729,16 +2729,29 @@
 t-node%22)
+%5D%0A      : %5B%5D)
 ,%0A  %5D,%0A%7D

fix config to work even in non-static or non production env