-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Replace browserify
with rollup
#28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea where the couple of bytes reduction is coming from? Is it just because this version doesn‘t build as a standalone-UMD bundle?
Looks like the bundle is output to stdout(4) on CI btw |
Actually I saw the same with browserify. Looks like something else prints code. Will check. |
The reduction comes from stripped debug I guess. It was not stripped with browserify in configuration. |
🤔 I didn't see that with browserify. It had a -o flag which wrote to a file I think? |
Debug is removed in the dist files already w babel, so that can't be it! |
lib was the input to browserify, not dist. So the size is grown a bit because of commonjs but we will achieve more optimisation after migrating to esm. |
Are you 100%? I checked that before. '.' Resolves to dest. You're saying this removes 20 bytes, but debug is much bigger than that so I have a hard time seeing it 🤔 tinyify is amazing, I can only understand the 20 byte shave coming from dropping the UMD bundle |
Ah, I see. You are right. I though main points to lib/index.js. Well, then I guess rollup just produces more optimal code then. |
Ah, and now it's in esm format, not cjs or umd. |
tinify is a set of optimisations around browserify + two passes of uglify. Btw I copy pasted it and passed to terser. Rollup does all optimisations out of the box. |
Here's per format sizes |
Hi thanks for your patience! I wanted to take a break from this repo after having lived in here for several months 😅
From these numbers, I conclude: So, what is the advantage of using rollup over browserify? The file from |
Afaik browserify cannot handle es modules without transpilation. Rollup supports only es modules out of the box. Migrating to esm will allow to scope hoist utilities, constants etc and make them mangleable. Browserify will probably not be able to show such reduction. Ps: Im on vacation for the next two weeks. Cannot rebase. |
Both true I believe.
I strongly doubt that ESM improves these things. The code is already written with this in mind, and common-shakeify can do it too. ESM is an improvement over UMD—it can shave those 17 bytes off in this bundle we’re checking. But that is not a cost anyone actually has: if you bundle code, you’re not getting those bytes because you’re not getting an UMD bundle. In fact, adding ESM would add bytes for every file for every user: unifiedjs/rfcs#4 (comment)? I do see ESM as the way forward. I personally don’t see it as better in any way though. It’s just the blessed way. If I am correct, and you’re interested in working on using ESM for micromark and compiling it with Rollup to CJS, then we’re getting another rollup config, correct? Would in then make sense to first do that while keeping browserify/tinyify (and maybe even keep on doing that in the future, or using both, so that we keep on comparing the same bundle that folks will typically get?)
Have fun, take care, and please don‘t respond yet unless you want to! |
Gotcha. The problem was here https://github.com/micromark/micromark/blob/main/lib/tokenize/block-quote.js#L50 Rollup wraps such dynamic usages with commonjs runtime which increased bundle size. Now rollup umd bundle is 13443 (against 13566 with browserify) |
Related-to GH-28. Closes GH-34. Reviewed-by: Marouane Fazouane <[email protected]> Reviewed-by: Titus Wormer <[email protected]>
Browserify: 13602 b Rollup: 13585 b Rollup is the best bundler to deal with es modules. In this diff I setup it before migrating sources to esm. Achieved size is the same. The config will be reused to produce cjs/esm entry points.
This comment has been minimized.
This comment has been minimized.
Hi @wooorm Is it good to go? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Thanks for your patience. Couple Qs and I’ll try this out locally now!
package.json
Outdated
"generate": "npm run generate-constant-typings && npm run generate-expressions && npm run generate-dist && npm run generate-size", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"format": "remark . -qfo && prettier --write . --loglevel warn && xo --fix", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"format": "remark . -qfo && prettier --write . --loglevel warn && xo --fix", | |
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logs all output instead of writing.
mangle: { | ||
safari10: true | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you see differences for using terser
twice? tinyify is running it on separate files, and on the whole, but this does the same twice. Maybe this isn’t noticable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
13425 vs 13589. But yeah, single pass is more realistic for user build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh, that’s significant! Weird! Well, let’s leave it in then
Also: running |
|
|
It works. Thanks. Btw lockfile allows to avoid this. |
I have only heard of this error for folks using yarn. Can you confirm whether that was the case? Comparing your branch to main, I’m now getting:
Rollup/terser removes 43 bytes! Nice, but pretty small. Again: ESM is the future, but that is soooo small. ESM isn’t better than CJS at tree shaking 🙄 |
Ah, actually you are right. I'm tied to yarn lockfiles 😄
It's 13386 with simplified blockquote and list exports. And remember, the code is still commonjs. Rollup may do less assumptions about safe commonjs transformations. Maybe it's also new commonjs plugin version. |
Yeah, you’re right! Maybe that’ll help! |
package.json
Outdated
"generate": "npm run generate-constant-typings && npm run generate-expressions && npm run generate-dist && npm run generate-size", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"format": "remark . -qfo && prettier . --write --loglevel warn && xo --fix", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"format": "remark . -qfo && prettier . --write --loglevel warn && xo --fix", | |
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", |
haha, you really like the long form 😅 If you feel strongly, I’m fine with it. Otherwise, you can apply this suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, short form works with reinstalled node_modules. Probably was a bug in old prettier. But yeah, let's use long version for consistency :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm, the consistency is that short flags are used where possible, and it was that way before, hence why I’m suggesting to go back to how it was 😅
Anyway, feel free to commit this suggestion, or not. I think the rest looks good. Is this PR ready to go? Anything else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other script --write was used
mangle: { | ||
safari10: true | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh, that’s significant! Weird! Well, let’s leave it in then
Awesome, thanks @TrySound! |
* Add tests for local babel plugins * Replace babel w/ rollup * Remove unused constant Related-to unifiedjs/rfcs#4. Related-to GH-27. Related-to GH-28. Closes GH-35. Reviewed-by: Titus Wormer <[email protected]>
Browserify: 13602 b
Rollup: 13585 b
Rollup is the best bundler to deal with es modules. In this diff I setup
it before migrating sources to esm. Achieved size is almost the same.
The config will be reused to produce cjs/esm entry points.