import babel from 'rollup-plugin-babel';
import replace from 'rollup-plugin-replace';
import bundleSize from 'rollup-plugin-bundle-size';
import { terser } from 'rollup-plugin-terser';

const IS_DEV = process.env.NODE_ENV === 'development';
const dir = IS_DEV ? 'tests/visual/dist' : 'dist';

const umdBundle = minify => ({
  input: 'src/index.js',
  plugins: [
    babel(),
    replace({
      __DEV__: "process.env.NODE_ENV !== 'production'",
    }),
    minify && terser(),
    bundleSize(),
  ].filter(Boolean),
  output: {
    name: 'Popper',
    file: `${dir}/umd/index${minify ? '.min' : ''}.js`,
    format: 'umd',
    sourcemap: true,
  },
});

const esBundle = minify => ({
  input: 'src/index.js',
  plugins: [
    babel(),
    replace({
      __DEV__: "process.env.NODE_ENV !== 'production'",
    }),
    minify && terser(),
    bundleSize(),
  ].filter(Boolean),
  output: {
    name: 'Popper',
    file: `${dir}/es/index${minify ? '.min' : ''}.js`,
    format: 'es',
    sourcemap: true,
  },
});

const cjsBundle = minify => ({
  input: 'src/index.js',
  plugins: [
    babel(),
    replace({
      __DEV__: "process.env.NODE_ENV !== 'production'",
    }),
    minify && terser(),
    bundleSize(),
  ].filter(Boolean),
  output: {
    file: `${dir}/cjs/index${minify ? '.min' : ''}.js`,
    format: 'cjs',
    sourcemap: true,
  },
});

const devBundle = () => ({
  input: 'src/index.js',
  plugins: [
    babel(),
    replace({
      __DEV__: 'true',
    }),
  ],
  output: {
    name: 'Popper',
    file: `${dir}/es/index.js`,
    format: 'es',
    sourcemap: true,
  },
});

const builds = IS_DEV
  ? [devBundle()]
  : [
      umdBundle(),
      umdBundle(true),
      esBundle(),
      esBundle(true),
      cjsBundle(),
      cjsBundle(true),
    ];

export default builds;

@@ -292,17 +292,23 @@
 %0A%0Aconst 
-u
+createU
 mdBundle
@@ -301,39 +301,50 @@
 reateUmdBundle =
+ (%7B
  minify
+ %7D = %7B%7D)
  =%3E (%7B%0A  input: 
@@ -418,47 +418,33 @@
 __: 
-%22process.env.NODE_ENV !== 'production'%22
+minify ? 'false' : 'true'
 ,%0A  
@@ -663,35 +663,24 @@
  esBundle = 
-minify =%3E (
 %7B%0A  input: '
@@ -802,32 +802,8 @@
 %7D),%0A
-    minify && terser(),%0A
     
@@ -895,39 +895,16 @@
 es/index
-$%7Bminify ? '.min' : ''%7D
 .js%60,%0A  
@@ -938,33 +938,32 @@
 ap: true,%0A  %7D,%0A%7D
-)
 ;%0A%0Aconst cjsBund
@@ -971,19 +971,8 @@
 e = 
-minify =%3E (
 %7B%0A  
@@ -1102,32 +1102,8 @@
 %7D),%0A
-    minify && terser(),%0A
     
@@ -1176,39 +1176,16 @@
 js/index
-$%7Bminify ? '.min' : ''%7D
 .js%60,%0A  
@@ -1220,33 +1220,32 @@
 ap: true,%0A  %7D,%0A%7D
-)
 ;%0A%0Aconst devBund
@@ -1253,15 +1253,8 @@
 e = 
-() =%3E (
 %7B%0A  
@@ -1453,33 +1453,32 @@
 ap: true,%0A  %7D,%0A%7D
-)
 ;%0A%0Aconst builds 
@@ -1504,25 +1504,22 @@
 ndle
-()
 %5D%0A  : %5B
-%0A      u
+createU
 mdBu
@@ -1529,118 +1529,63 @@
 e(),
-%0A      umdBundle(true),%0A      esBundle(),%0A      esBundle(true),%0A      cjsBundle(),%0A      cjsBundle(true),%0A    
+ createUmdBundle(%7B minify: true %7D), esBundle, cjsBundle
 %5D;%0A%0A

remove minification for cjs/es, create two umd bundles