import type * as esbuild from "esbuild"

export const externalDep = (externals: string[]): esbuild.Plugin => ({
  name: "externalDep",
  setup(build) {
    for (const module of externals) {
      const resolved: esbuild.OnResolveResult = {
        path: `/vendor/${module}/index.js`,
        external: true,
      }
      build.onResolve({ filter: RegExp(`^${module}$`) }, () => resolved)
    }
  },
})
