import styles from 'rollup-plugin-styles';
const autoprefixer = require('autoprefixer');
import babel from '@rollup/plugin-babel';
import json from '@rollup/plugin-json';
import image from '@rollup/plugin-image';
import localResolve from 'rollup-plugin-local-resolve';

// the entry point for the library
const input = 'src/index.js';

var MODE = [
  {
    fomart: 'cjs',
  },
  {
    fomart: 'esm',
  },
  {
    fomart: 'umd',
  },
];

var config = [];

MODE.map((m) => {
  var conf = {
    input: input,
    output: {
      // then name of your package
      name: '@plusscommunities/pluss-maintenance-web',
      file: `dist/index.${m.fomart}.js`,
      format: m.fomart,
      exports: 'auto',
    },
    // this externelizes react to prevent rollup from compiling it
    external: ['react', /@babel\/runtime/],
    plugins: [
      // these are babel comfigurations
      babel({
        exclude: 'node_modules/**',
        presets: ['@babel/preset-react', '@babel/preset-env'],
        plugins: ['@babel/transform-runtime'],
        babelHelpers: 'runtime',
      }),
      // this adds support for styles
      styles({
        postcss: {
          plugins: [autoprefixer()],
        },
      }),
      json(),
      image(),
      localResolve(),
    ],
  };
  config.push(conf);
});

export default [...config];
