const resolve = require("@rollup/plugin-node-resolve");
const commonjs = require("@rollup/plugin-commonjs");
const alias = require("@rollup/plugin-alias");
const terser = require("@rollup/plugin-terser");
const path = require("path");

const plugins = [
  alias({
    entries: [
      {
        find: "../lib/read-wasm",
        replacement: path.resolve(__dirname, "read-wasm-inline.js"),
      },
      {
        find: "./url",
        replacement: path.resolve(__dirname, "url-browser.js"),
      },
    ],
  }),
  resolve({ browser: true }),
  commonjs(),
];

module.exports = [
  {
    input: "source-map.js",
    output: {
      file: "dist/source-map.js",
      format: "umd",
      name: "sourceMap",
      exports: "named",
    },
    plugins,
  },
  {
    input: "source-map.js",
    output: {
      file: "dist/source-map.min.js",
      format: "umd",
      name: "sourceMap",
      exports: "named",
      sourcemap: true,
    },
    plugins: [...plugins, terser()],
  },
];
