-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--compress true - is it a good default? #66
Comments
The goal of microbundle is primarily to package tiny modules that are used in a browser context. In this respect, minification is the most logical default. |
Don’t know if it is possible but maybe only the UMD build should be minified, given that the CJS and ESM version mostly imply the consumer is using a bundler ? |
It's certainly possible and what would be a good fit here. I propose 3 possible values of compress option:
|
Another option that might be worth adding is a way to do I'm thinking that might be a sensible default if passing |
Will work on this, once #62 gets merged (it has improved support for tests) - and we will be able to discuss further under the PR about used approach. |
I don't think it's clear enough this is intended for browser usage due to the default "target" being "node" (this option isn't really explained?) I kind of assumed it would gracefully handle builtins, but it doesn't. |
Came here with the same issue when bundling for node.
Really weird to see this when default target is |
A way to opt out of minification would be useful for debugging. |
Instead of an all or nothing $ microbundle src --format cjs,umd,iife --compress umd,iife
#=> CJS is the only unminified Not specifying any groups would assume all formats want compression. This way it's not breaking~! $ microbundle src
#=> all (default) formats compressed
$ microbundle src --compress
#=> (redundant) compress=true ==> all formats |
IMHO this would bloat CLI api a lot. Every other current (and future) option would "need" to support it, adding this to a single option would look weird. It also closes a little bit things like mentioned I think microbundle should provide most reasonable defaults with not that many configurable parts (although I don't really believe in 0 configuration tools, so actually I might propose some more advanced ways to customize in the future). If you need such fine-grained control, passing different options' values for different formats etc you can always just have 2 microbundle scripts instead of 1, each targeting specific subset of formats. |
Hmmm, not so sure that I agree with the idea that current options would need to support this. Of all our options, only Personally, I'm totally fine with the current |
Imho both strict & external could be considered as those that should support it. Also your proposed option regarding source map generation. |
Yeah I suppose. Fair enough 😄 |
I've never used |
Watch mode minifies by default. You can always turn off minification by passing |
It would be helpful to document |
I'm just not a big fan of Ideally, here, we'd (1) skip compression for |
|
yes, I feel like a lot of people are using microbundle to publish to npm and I don't really see minification as a good default there, had problems with it myself, especially before I fixed sourcemaps |
re: 2) I actually feel that compression should be off for |
I ran a Twitter poll, and it looks like web is the majority of microbundle's use-case. That means the majority of Microbundle users expect minification by default - I'd actually suggest that's one of the primary reasons people use this tool. https://twitter.com/_developit/status/1029460914897076224 Some things to consider: Defaults are everythingMicrobundle has a fair number of users already, and the reason they're using it is because of the default output. Changing the default output changes the project. There are lots of other alternatives people can/could choose, so if folks are using Microbundle it's very likely because of the simple optimized-by-default output. I think Not all minification is equalIt is exceptionally rare to see developers enable property mangling when minifying their applications. Microbundle incorporates configurable property mangling that is rather difficult to set up using Uglify directly, as evidenced by the fact that most library authors don't use it. I would be inclined to make property mangling easier before removing minification by default. Microbundle is actually a size tracking utility tooSize is an important metric for library authors, and showing size without minification and compression is meaningless. Applications that care about performance minify and compress their JavaScript, and the size relationship there is non-linear. Anyone authoring a library that is used in a browser environment has a responsibility to track the minified + compressed size of that library so that their users can make informed decisions about the cost efficacy of installing their module. Since Microbundle caters specifically to that use-case, the responsibility falls to us. Watch modeAbout re: documetation - I definitely agree that the help output and README should document flags using their "on" values (" |
Are you sure people expect minification when they target browsers? I definitely target browsers with parket, but I never really wanted it to be minified |
You are not alone, I edit
👍 Same here, main target is browser but at the same moment the main target are modern bundlers and I don't want to feed them with minified source (mainly because harder debugging & node_modules editing)
I believe that is the main reason why people use microbundle - because it's 0 config and most people struggle with configs because usually they need deeper understanding of the tool. This doesnt immediately imply that current defaults are what people actually want.
Agreed, but maybe this should be responsibility of another tools? uglify presets or smth?
Tracking size doesnt have to happen on directly distributed files though. I.e https://github.com/TrySound/rollup-plugin-size-snapshot allows for tracking minified+gzipped code but it doesnt change the output files in any way (so they stay unminified). |
I answered the poll but like andarist I target browsers through bundlers so I don’t expect minification except for the umd build (for unpkg usage). |
Just to chime in, I chose Microbundle because of the zero config. I use it to develop React libraries that are ultimately targeting the browser via a bundler. Would love a best of both worlds where minimal/zero config is maintained but industry standards are achievable for minification etc. Loving the simplicity of using Microbundle! |
Our conversation is kinda split, but I'll come back here since this is where most of the chat lives :) Good points all around, and I'd totally be a happy camper any way forward. I think the best combination of behaviors, spanning all points, is perhaps the following:
|
My opinion is |
+1 for both
I'd like to introduce a special |
Idea What if w could satisfy both worlds and just provide both minified & unminified versions by creating a proxy entry such as this import * as dev from "./dist/${packageName}.development.mjs"
import * as prod from "./dist/${packageName}.production.min.mjs"
${exports.map(name => `
export var ${name} = process.env.NODE_ENV !== 'production' ? dev.${name} : prod.${name}
`).join('\n')} (snippet originally authored by @TrySound, this would have to handle default export differently, but it's easy to adjust this) Downsides If the package is not entirely tree-shakeable then the consumers would have to probably pay twice the price of that (unused things in both prod & dev bundles would have to be added to the final bundle). OTOH w can detect such a situation & warn/educate people on what they can do to make libraries tree-shakeable. |
Reviving this one as was a tripped up. As perhaps hinted at earlier, could we let the filename of each target define its requirement? So if suffixed with |
Hey @developit, running into this as well. I think @lukeed has a point about allowing for different compression configurations by format. But I also recognize your goals which are super valid in terms of ease of use and bundle size.
I think there's a way to satisfy all of those... Change the compression defaults.One of the issues is that people expect to receive non-minified code in the (Yes sourcemaps help a bit, but they don't help when you need to edit files in But at the same time, people also assumed that there is a minified UMD build available to quickly use on the web.
Change the bundle size output.The other issue I think is that the bundle size print outs from the CLI once for each type of format used. This makes sense from a mental model standpoint, and is easy to implement, but it's also not exactly the best solution for many of the use cases. As a user I have to read through three extremely similar sizes—similar enough that I don't really care about the minute differences. And none of the sizes are the "true" cost of the module anyways, because that size depends on what it is bundled with—they're just an estimate. I propose that we instead print out only one estimated size. And that that size ignores the wrapper parts of the bundling code, giving you the "truest" size estimate for the package's impact on a bundle. For example:
I think this would actually be a UX improvement when using (You could always have a Those two changes allow compression to be toggled by format. And by decoupling the size calculation from the individual files output you can maintain consistent size tracking regardless of flags being toggled. At least that seems to solve everyone's concerns I think. |
This makes any library that uses microbundle insanely difficult to debug. Please add this option. |
Apologies for letting this issue drop - there are a few open issues/PR's discussing the topic, I think this one just got buried. @ianstormtaylor I totally agree on the size display thing. I think it would be reasonable to have Microbundle only output the size for the ESM build, unless that build is specifically omitted via Regarding I've left some comments over on #187 with potential ways this can be moved forward, for those interested. The TLDR is that package authors can be reasonably confident that their users will have basic whitespace and identifier mangling in place, so we should do property mangling and optimization/inlining in Microbundle but can preserve whitespace and identifiers in dist files. |
IMHO it makes debugging harder, its not easy to look into source code of libraries in node_modules (built by microbundle) nor it is easy to debug microbundle itself because its built by itself with --compress true (default).
I guess the question is what is a primary goal & target of this tool? If producing micro libraries then I think files should be left unminified by default, minifying can be done later by subsequent tools - bundlers etc.
The text was updated successfully, but these errors were encountered: