#Use modules for source when compiling with `--outFile`?

30 messages · Page 1 of 1 (latest)

carmine turtle
#

As per title; I want to compile to a single (UMD/web) file, but use modules internally for organisation; is there a way to do this? Ideally, no second build step

cedar kiln
#

I'll let you answer Retsam, you probably know better than me.

#

Re: outfile

stuck lodge
#

@carmine turtle Yeah, there isn't a direct way to do this, AFAIK. TS really isn't a bundler

#

So "outfile" is mostly limited to old-school style patterns where you're just concatenating source files together.

cedar kiln
#

Aha

stuck lodge
#

I would recommend a build tool, e.g. vite. You don't need it to be a "second" build step because it can handle TS inputs.

carmine turtle
#

What's the easiest way to set up a tool like vite? Any time I interact with vite normally I'm using a template that sets it up for me lol

stuck lodge
#

You can do npm create vite and it automatically downloads and runs a vite setup wizard

cedar kiln
#

Vite actually bundles using rollup. If you want to make a web app, then using vite for dev mode + using its build option with rollup makes sense.

stuck lodge
#

(npm create X is a npm command that that downloads and runs a package called create-X)

cedar kiln
#

If you literally just want to bundle some JS, I think you want rollup directly?

stuck lodge
#

Yeah, vite doesn't bundle in dev because that's generally a nicer experience.

carmine turtle
#

Yeah, Vite seems to have given me a bunch of extra stuff I don't need or want, so seems like Rollup is what I need

cedar kiln
#

Rollup should be pretty easy, like ~10 lines of config

#

Or less

#

Bun has a bundler built in I learned recently, if using that.

carmine turtle
carmine turtle
cedar kiln
stuck lodge
#

Vite can be used for just "library" usage and it's still helpful, but a lot of the vite stuff is aimed at website building/bundling.

cedar kiln
#

Bun claims to be very fast

stuck lodge
#

Yeah, it's probably not doing JS-based bundling like rollup is

cedar kiln
#

188x faster than rollup with terser. Surely it is doing less refinement though.

cedar kiln
stuck lodge
#

Not written in JS - the older generation of tools like babel and rollup are implemented in JS and are much slower than something that's implemeted in Go or Rust like esbuild or swc

cedar kiln
#

Right

#

Bun is built in Zig