import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";

const basePlugins = [
  resolve({
    mainFields: ["module", "main"],
    preferBuiltins: false,
    modulePaths: ["/usr/share/nodejs"]
  }),
  commonjs()
];

export default [
  {
    input: "index.mjs",
    external: id => !id.startsWith(".") && !id.startsWith("/") && !id.includes("index.mjs"),
    output: {
      file: "dist/dagre-d3.core.js",
      format: "cjs"
    },
    plugins: basePlugins
  },

  {
    input: "index.mjs",
    external: id => !id.startsWith(".") && !id.startsWith("/") && !id.includes("index.mjs"),
    output: {
      file: "dist/dagre-d3.core.min.js",
      format: "cjs"
    },
    plugins: [...basePlugins, terser()]
  },

  {
    input: "index.mjs",
    external: () => false,
    output: {
      file: "dist/dagre-d3.js",
      format: "umd",
      name: "dagreD3"
    },
    plugins: basePlugins
  },

  {
    input: "index.mjs",
    external: () => false,
    output: {
      file: "dist/dagre-d3.min.js",
      format: "umd",
      name: "dagreD3"
    },
    plugins: [...basePlugins, terser()]
  }
];

