import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from '@rollup/plugin-typescript'
import postcss from 'rollup-plugin-postcss'
import { terser } from 'rollup-plugin-terser'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import image from '@rollup/plugin-image';
import json from "@rollup/plugin-json";

const path = require('path')
const toPath = filePath => path.join(process.cwd(), filePath)

const packageJson = require('./package.json')

module.exports = [
  {
    input: 'src/index.ts',
    external: ['src/index.scss'],
    output: [
      {
        file: packageJson.main,
        format: 'cjs',
        sourcemap: true,
      },
      {
        file: packageJson.module,
        format: 'esm',
        sourcemap: true,
      },
    ],

    plugins: [
      peerDepsExternal(),
      resolve({
        dedupe: [
          '@emotion/core',
          toPath('node_modules/@emotion/react'),
          'emotion-theming',
          toPath('node_modules/@emotion/react'),
        ],
      }),
      commonjs(),
      json(),
      image(),
      typescript({ tsconfig: './tsconfig.json' }),
      terser(),
      postcss({
        plugins: [],
        minimize: true,
      }),
    ],
    external: ['react', 'react-dom'],
  },
]
