esbuild_deno_loader icon indicating copy to clipboard operation
esbuild_deno_loader copied to clipboard

"external" config option in esbuild broken

Open zefhemel opened this issue 2 years ago • 6 comments

When I configure external to be excluded from the bundle in my esbuilder config, they seem to be ignored when enabling the esbuild_deno_loader plugin. What I've done my local fork is add this:

if (build.initialOptions.external) {
  for (const external of build.initialOptions.external) {
    if (resolved.href.startsWith(external)) {
      return { path: resolved.href, external: true };
    }
  }
}

Above this line: https://github.com/lucacasonato/esbuild_deno_loader/blob/main/mod.ts#L77

This works, but isn't great, because external supports wildcards and what not. According to the esbuild docs this shouldn't be necessary, but I'm not familiar enough of how this all interacts to figure out why externals just seem to break without the lines above.

zefhemel avatar Oct 11 '22 11:10 zefhemel

Had to use this:

          if (build.initialOptions.external) {
            for (const external of build.initialOptions.external) {
              if ((resolved.href.startsWith(external)) || (args.path === external)) {
                return { path: resolved.href, external: true };
              }
            }
          }

in order to also ignore modules added to external by the name defined in the import map json file.

kilisio avatar Feb 16 '23 17:02 kilisio

I am running into this issue too. @lucacasonato any ideas on how to use esbuild_deno_loader with esbuild's external feature?

mfulton26 avatar May 19 '23 13:05 mfulton26

+1 this is also happening to me.

quinn avatar Dec 14 '23 23:12 quinn

Same here!

haschu avatar Dec 29 '23 20:12 haschu

@haschu I made a fork here which you can use: https://github.com/lucacasonato/esbuild_deno_loader/pull/95

import { denoPlugins } from 'https://raw.githubusercontent.com/quinn/esbuild_deno_loader/main/mod.ts'

YMMV. it is tailored to my usecase, which is to pass the import through untouched (rather than being resolved by deno's import map, then left as an import)

quinn avatar Dec 29 '23 22:12 quinn

Would very much appreciate if this could be fixed as PeerJS has one link for both Deno and the web, but when bundling it seems to include node:process and node:buffer. Being able to exclude it from being bundled in would simply solve that problem.

This code in the browser works, but when bundled, breaks.

import { Peer } from "https://esm.sh/[email protected]?bundle-deps"

const peer = new Peer()
console.log(peer.id)

BlackAsLight avatar Jan 20 '24 13:01 BlackAsLight