import typescript from '@rollup/plugin-typescript';
import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';

const input = 'src/memoize-one.ts';
const tsPlugin = () => typescript({ module: 'ESNext' });

export default [
  {
    input,
    output: {
      file: 'dist/memoize-one.js',
      format: 'umd',
      name: 'memoizeOne',
    },
    plugins: [
      replace({
        'process.env.NODE_ENV': JSON.stringify('development'),
        preventAssignment: true,
      }),
      tsPlugin(),
    ],
  },
  {
    input,
    output: {
      file: 'dist/memoize-one.min.js',
      format: 'umd',
      name: 'memoizeOne',
    },
    plugins: [
      replace({
        'process.env.NODE_ENV': JSON.stringify('production'),
        preventAssignment: true,
      }),
      tsPlugin(),
      terser(),
    ],
  },
  {
    input,
    output: {
      file: 'dist/memoize-one.esm.js',
      format: 'esm',
    },
    plugins: [tsPlugin()],
  },
  {
    input,
    output: {
      file: 'dist/memoize-one.cjs.js',
      format: 'cjs',
      exports: 'default',
    },
    plugins: [tsPlugin()],
  },
];
