infinitered / gluegun

A delightful toolkit for building TypeScript-powered command-line apps.
MIT License
2.97k stars 147 forks source link

Add Rollup (or similar) to gluegun-generated CLIs to ship smaller CLIs #287

Open jamonholmgren opened 6 years ago

jamonholmgren commented 6 years ago

By adding Rollup to our generated CLIs, it would allow us to tree-shake and bundle only the code that is used into one (smaller) shipped bundle.

jamonholmgren commented 6 years ago

I played with it some tonight, but am not finding much info online about making Rollup work with a Node-powered CLI. I was able to get it to run, but it just copied the src/cli.js into the build folder and didn't actually roll anything up.

skellock commented 6 years ago

Do you have some code I can look at?

jamonholmgren commented 6 years ago

I deleted it. No git backup.

oops

I can pretty easily recreate what I had, though. I'll do that and throw it into a repo for you, @skellock .

skellock commented 6 years ago

What I’m thinking is perhaps we start the roll up bundle at the 2nd file and not the cli entry point.

We have our bin/{brand} file and then our {bundle}.

Not sure if that will matter.

I’ve used rollup on several libs and it’s awesome. But never on a cli before.

jamonholmgren commented 6 years ago

That’s actually what I did, started at the second file (cli.js). It just only included that file, though. Not sure what I’m doing wrong. I’ll post code next week.

jamonholmgren commented 6 years ago

@skellock https://github.com/jamonholmgren/gluegun-movies-demo/commit/b071780bd190ce9fb9ac52f5010a2d0088321c03#diff-6e46529c2666be7cf13a3484f3722052R12

jamonholmgren commented 6 years ago

Shipped gluegun with Rollup! However, it doesn't close this issue, as we don't include Rollup in generated CLIs. Keeping this zombie caged.

yordis commented 5 years ago

@jamonholmgren I would add as part of this improvement the TypeScript definitions to the output.

Even when you are using the JavaScript version, by adding the TypeScript spec some editors could give you an analysis of gluegun dependency.

Also, disable removeComments from the tsconfig since that will remove the inline documentation of the code.

Coming from Elixir, I would love to see npm packages shipping with the inline documentation in the source code. Especially if the package is meant to be used in NodeJS ecosystem where the file sizes do not matter as much as the browser (in any case, your build pipeline could remove the documentation).

I am suffering from this details since either I have to go to Github to figure out the code or I have to put console.log and hopefully I can find the info that I need.

jthegedus commented 5 years ago

Instead of shipping Rollup by itself to all gluegun CLI creators, might I suggest using https://github.com/developit/microbundle, or something like it, to reduce the burden of users to configure Rollup?

jamonholmgren commented 5 years ago

microbundle looks really cool @jthegedus. I'd definitely consider it.