evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
38.08k stars 1.14k forks source link

How to output whole module graph when bundle: false? #3826

Open hesxenon opened 3 months ago

hesxenon commented 3 months ago

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?

evanw commented 2 months ago

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.