Skip to content
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

Merged
merged 11 commits into from
Nov 19, 2020
Merged

Replace browserify with rollup #28

merged 11 commits into from
Nov 19, 2020

Conversation

TrySound
Copy link
Contributor

@TrySound TrySound commented Oct 12, 2020

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.

Copy link
Member

@wooorm wooorm left a 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?

@wooorm
Copy link
Member

wooorm commented Oct 12, 2020

Looks like the bundle is output to stdout(4) on CI btw

@TrySound
Copy link
Contributor Author

Actually I saw the same with browserify. Looks like something else prints code. Will check.

@TrySound
Copy link
Contributor Author

The reduction comes from stripped debug I guess. It was not stripped with browserify in configuration.

@wooorm
Copy link
Member

wooorm commented Oct 12, 2020

🤔 I didn't see that with browserify. It had a -o flag which wrote to a file I think?

@wooorm
Copy link
Member

wooorm commented Oct 12, 2020

Debug is removed in the dist files already w babel, so that can't be it!

@TrySound
Copy link
Contributor Author

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.

@wooorm
Copy link
Member

wooorm commented Oct 12, 2020

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

@TrySound
Copy link
Contributor Author

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.

@TrySound
Copy link
Contributor Author

Ah, and now it's in esm format, not cjs or umd.

@TrySound
Copy link
Contributor Author

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.

@TrySound
Copy link
Contributor Author

Here's per format sizes
Browserify: 13602 b
Rollup esm: 13585 b
Rollup cjs: 13594 b
Rollup umd: 13685 b

@wooorm
Copy link
Member

wooorm commented Oct 20, 2020

Hi thanks for your patience! I wanted to take a break from this repo after having lived in here for several months 😅

Here's per format sizes
Browserify: 13602 b
Rollup esm: 13585 b [100b off from rollup umd, 17b off from browserify umd]
Rollup cjs: 13594 b [91b off from rollup umd, 8b off from browserify umd]
Rollup umd: 13685 b [83b bigger than browserify umd]

From these numbers, I conclude:
a) browerify does not output CJS/ESM or this isn’t checked.
b) rollup performs worse than browserify on comparable targets
c) the saving come from checking a different target: CJS or ESM over UMD.

So, what is the advantage of using rollup over browserify? The file from generate-size is not published: the numbers are used to check how big micromark would be in a browser. Switching to a different bundler/minifier will yields slightly different results, but that is unrelated to micromark.

@wooorm wooorm added 🏗 area/tools This affects tooling 🙉 open/needs-info This needs some more info labels Oct 20, 2020
@TrySound
Copy link
Contributor Author

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.

@wooorm
Copy link
Member

wooorm commented Oct 28, 2020

Afaik browserify cannot handle es modules without transpilation. Rollup supports only es modules out of the box.


Both true I believe.


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.


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?)

Ps: Im on vacation for the next two weeks. Cannot rebase.

Have fun, take care, and please don‘t respond yet unless you want to!

@TrySound
Copy link
Contributor Author

TrySound commented Nov 2, 2020

Gotcha. The problem was here

https://github.com/micromark/micromark/blob/main/lib/tokenize/block-quote.js#L50
https://github.com/micromark/micromark/blob/main/lib/tokenize/list.js#L155

Rollup wraps such dynamic usages with commonjs runtime which increased bundle size.

Now rollup umd bundle is 13443 (against 13566 with browserify)

wooorm pushed a commit that referenced this pull request Nov 11, 2020
Related-to GH-28.
Closes GH-34.

Reviewed-by: Marouane Fazouane <[email protected]>
Reviewed-by: Titus Wormer <[email protected]>
@wooorm wooorm mentioned this pull request Nov 11, 2020
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.
@codecov-io

This comment has been minimized.

@TrySound
Copy link
Contributor Author

Hi @wooorm Is it good to go?

Copy link
Member

@wooorm wooorm left a 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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"format": "remark . -qfo && prettier --write . --loglevel warn && xo --fix",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",

Copy link
Contributor Author

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
}
})
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

@wooorm
Copy link
Member

wooorm commented Nov 18, 2020

Also: running npm test on the code here reformats a couple of comments/style things

@TrySound
Copy link
Contributor Author

$ remark . -qfo && prettier . --write --loglevel warn && xo --fix
Error: Failed to load plugin 'prettier' declared in 'CLIOptions': Cannot find module 'eslint-plugin-prettier'

@wooorm
Copy link
Member

wooorm commented Nov 18, 2020

rm -rf node_modules && npm i?

@TrySound
Copy link
Contributor Author

It works. Thanks. Btw lockfile allows to avoid this.

@wooorm
Copy link
Member

wooorm commented Nov 18, 2020

lockfiles

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:
13.4 kB
13436

browserify / tinyify:
13.5 kB
13479

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 🙄

@TrySound
Copy link
Contributor Author

TrySound commented Nov 18, 2020

I have only heard of this error for folks using yarn. Can you confirm whether that was the case?

Ah, actually you are right. I'm tied to yarn lockfiles 😄

Rollup/terser removes 43 bytes! Nice, but pretty small.

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.

@wooorm
Copy link
Member

wooorm commented Nov 18, 2020

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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

Copy link
Contributor Author

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 :)

Copy link
Member

@wooorm wooorm Nov 19, 2020

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?

Copy link
Contributor Author

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
}
})
Copy link
Member

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

@wooorm wooorm changed the title Replace browserify with rollup Replace browserify with rollup Nov 19, 2020
@wooorm wooorm merged commit 91745b4 into micromark:main Nov 19, 2020
@wooorm
Copy link
Member

wooorm commented Nov 19, 2020

Awesome, thanks @TrySound!

@wooorm wooorm added ⛵️ status/released 🦋 type/enhancement This is great to have and removed 🙉 open/needs-info This needs some more info labels Nov 19, 2020
wooorm pushed a commit that referenced this pull request Nov 20, 2020
* 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]>
@wooorm wooorm added the 💪 phase/solved Post is done label Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏗 area/tools This affects tooling 💪 phase/solved Post is done 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

3 participants