esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

How to output whole module graph when bundle: false?

Open hesxenon opened this issue 1 year ago • 1 comments

I'm having trouble figuring out how to basically copy the whole library and transpile it along the way without bundling.

The reason for why I don't want to enable bundling is to enable downstream projects to utilize tree shaking as much as possible (i.e. I don't want to deal with that).

Just using tsc without an outdir has been fine so far but now I need to have multiple outdirs and that obviously breaks my asset imports. Rather than watching those assets myself and copying them into each outdir on change I thought I'd just use esbuild for that only to notice that bundle: false only copies the entrypoints instead of everything that's referenced by that entrypoint.

So given the following input

import "./index.css";
import "./foo.js";

and

/* index.css */
.foo {
  mask-image: url("./assets/icon.svg");
}

what I'd like to have in my outdirs is

/index.js # mostly unchanged except for stripped typings
/foo.js
/index.css
/assets/icon.svg

Is there a way to enable that with esbuild?

hesxenon avatar Jul 08 '24 11:07 hesxenon

You are welcome to bundle things and then not use the resulting bundle (and not write the bundle to the file system, with write: false). But bundling is required for esbuild to process the whole module graph. If you don't bundle, then esbuild doesn't traverse through the module graph at all.

evanw avatar Aug 16 '24 19:08 evanw