import resolve from '@rollup/plugin-node-resolve';
import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import terser from '@rollup/plugin-terser';
import external from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
import image from '@rollup/plugin-image';
import svgr from '@svgr/rollup';
import nodePolyfills from 'rollup-plugin-node-polyfills';

import packageJson from './package.json' assert { type: 'json' };

export default {
  input: 'src/index.js',
  output: [
    {
      file: packageJson.main,
      format: "cjs",
      sourcemap: true,
    },
  ],
  plugins: [
    commonjs({
      include: /node_modules/,
    }),
    babel({
      plugins: ["@babel/plugin-transform-runtime"],
      exclude: "node_modules/**",
      presets: ["@babel/preset-react", "@babel/preset-env"],
      babelHelpers: "runtime",
    }),
    external(),
    resolve({
      browser: true,
    }),
    postcss(),
    terser(),
    image(),
    json(),
    svgr({ exportType: 'named', jsxRuntime: 'automatic' }),
    nodePolyfills(),
  ]
}
