-
Notifications
You must be signed in to change notification settings - Fork 361
Replace bublé with babel #263
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
Conversation
Yes, size is important that's why we currently only use babel for async await |
src/index.js
Outdated
], | ||
}), | ||
babel( | ||
(await isFile('.babelrc')) || (await isFile('.babelrc.js')) |
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.
seems like it should get hidden in the separate function as the logic here is complex-ish and its hard to read when its inlined
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.
also this is not quite the only way to configure babel - there is also babel.config.js
and babel
key in the package.json
I think there is some API in babel@7 to detect if there is any configuration for the project. Maybe you could search for it to see if it meets our needs, you could also try to research what storybooks and babel-jest are doing atm (although both may have custom implementations and it would better to use babel-provided one if possible)
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.
after a thought - we should make our internal babel config a public babel-preset-microbundle
, but should be done in a followup review - because it will require setting up a monorepo.
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.
ohh I like that idea of a dedicated microbundle
preset 👍
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.
@Andarist Could we expose something like https://github.com/babel/babel-loader/#customized-loader from rollup-plugin-babel
? I think it is very bad to encourage frameworks to implement their own resolution for .babelrc
files and such, since it doesn't necessarily conform to Babel's own implementation details.
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.
@Andarist Could we expose something like https://github.com/babel/babel-loader/#customized-loader from rollup-plugin-babel?
Sure, gonna look through this to see what it actually is & how it can be used to achieve goals here.
I think it is very bad to encourage frameworks to implement their own resolution for .babelrc files and such, since it doesn't necessarily conform to Babel's own implementation details.
Totally agreed - I was only pointing to babel-jest & others to see how similar goal is achieved. It's 100% better to reuse the logic in babel itself to avoid buggy implementations.
Could u paste in formatted output of a single failed snapshot pre & post this PR? We could see where lies the difference in transpiling and decide how to proceed further with this. Thanks for your work! |
Thanks for the excellent review @Andarist! 👏 I'll update the PR later today and we can discuss how to proceed further. |
90fab42
to
ba4ceab
Compare
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.
The PR has now been updated with the requested changes.
I found a function in @babel/core
called loadPartialConfig that enables validation of configuration files. This is a documented API and is pretty much what we are looking for. Please note the discussion I started in the new diff, however.
The snapshot diffs have now been pushed for your commenting pleasure. After perusing them one more time, it seems not all the diffs are up, some are in fact down. So it's a lot more of a mixed bag than I originally thought. We may still want to look into reducing the file size, though, I'm open for suggestions here.
@@ -226,6 +226,45 @@ export default async function microbundle(options) { | |||
); | |||
} | |||
|
|||
function createBabelConfig(options) { | |||
const partialConfig = loadPartialConfig(); | |||
const hasBabelConfigFile = partialConfig.hasFilesystemConfig(); |
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.
Note that this function does not respect the babel
field in package.json. The only way I can see is adding a special case for detecting this field. Thoughts?
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.
The thing is that loadPartialConfig
is meant to be called per-file, because some files may have a .babelrc
and some may not. That is what drove my comment above. It seems like rollup-plugin-babel
should be exposing this as a feature, which is what we do for babel-loader
so that people can do the same thing.
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.
@loganfsmyth: I see, thanks for the clarification. So if we go for that solution, that would mean this is impeded on rollup-plugin-babel
exposing this feature.
I can make an issue over at rollup-plugin-babel to the best of my ability and see where that takes us.
As to the snapshots - it would be great to see comparisons of the output code, not the size differences. The PR looks really good, we "only" (from my perspective, other collaborators have to state their minds too about this) need to investigate size differences and implement config loading related feature in rollup-plugin-babel (im a maintainer, so we should be able to move with it quickly if u want to work on it or I can research the topic in a few days and implement it myself) |
Here's the list of changes to the compiled output from the tests before and after this change. It's formatted with prettier to make it easier to read, so the linked gists will not match 1-1 with the bytes listed in the table below. The byte sizes below are the file sizes of the
|
|
ba4ceab
to
9e3ee15
Compare
Yes, compilation of TypeScript files was missing from the rollup-plugin-babel extension set. Fixed that now and updated the gist and the output comment with updated file sizes. TS is now up in size, except for decorators, which is now flat. One annoyance that popped up now is the failing test, see below. This seems to be the same issue as rpetrich/babel-plugin-transform-async-to-promises#20
|
Additional note - babel wraps transpiled class in an IIFE which increases the size a little bit, BUT by adding #PURE comments to those IIFEs it makes them treeshakable (so its superior in this sense to buble). Unfortunately static assignments, such as assignments to prototypes, deopts most treeshaking/DCE algorithms so its better to avoid those in top level scope. |
9e3ee15
to
5951baa
Compare
A bunch of them fall into the 7.2% increase that I think is worth figuring out. I don't think the Array preallocation is actually beneficial in the case of arguments - Buble was right in doing a backwards loop, since that results in the Array being initialized and immediately set to the correct length (largest index first). Perhaps we can get Babel to change its output format for rest parameters? |
I've opened a PR to Babel to make the outputs align: babel/babel#9152 |
According to the latest comment in rpetrich/babel-plugin-transform-async-to-promises#20, the issue with the failing test should be fixed. I just tried running the I scanned through the diffs, and I see the "before" (bublé) has async/await in the output! The "after" (babel) does not. This obviously results in the babel output being much, much larger. It seems async/await with typescript is bugged on HEAD of master (210bb00), at least in this test. Maybe related to #259? I'll push the new output to the main gist once |
@esphen A good portion of that output is |
@rpetrich Thanks for the tip. I tried setting typescript's target to I would like to hear from the other maintainers before we hand over responsibility of compiling ES from the ts plugin to babel, however. Currently typescript only compiles to ES2017, then bublé/babel does the rest. Any good reason it is done this way currently? |
Could you rebase on top of the master?
I guess the reasoning is to strip types with TS and do the actual transpilation to ES5 with buble/babel |
} | ||
|
||
// No babelrc exists, use default config | ||
// TODO move this into a separate babel-preset-microbundle package |
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.
Could we start by moving this into its own file?
], | ||
], | ||
}), | ||
babel(createBabelConfig(options)), | ||
{ | ||
// Custom plugin that removes shebang from code because newer |
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 we still need this? If yes maybe it's worth to update the comment to explain why
I sent a PR to @esphen's branch to rebase to master (eliihen#1) |
New test results are in. I've merged @FezVrasta's changes and updated the comment on the output sizes above. Notable changes:
|
@esphen have you updated the comparison table with new versions of those outputs? I might compare them later. |
@Andarist Yes, both the comparison table and the gist are up to date |
# Conflicts: # package.json # src/index.js # test/__snapshots__/index.test.js.snap
@ForsakenHarmony @developit do we want this getting merged? I can put my teeth in it as we want this for gatsbyjs too so we can add our own babelrc file or will we still keep babelrc false? |
@wardpeet yeah. We definitely still want to move off Bublé. |
Hello 👋
First of all - thank you so much for this project, it makes following best practices when packaging libraries for npm really easy!
I saw the PR at #39 and thought I should help out by merging in the latest code from master and getting it up to date. However, a lot seems to have changed since #39 was created, so it was actually a lot easier to start from scratch. So that's what I did, and in this branch it now works with babel 7.
Reading the discussion in #39, I interpreted @developit's comment as intent to replace bublé with babel, so that's what this PR does.
The generated configuration uses a default babel config consisting of preset-env and preset-react, alongside the existing plugins for async/await support. If a babel config file is detected, it uses a clean slate. I hope this is a sensible starting point; free to suggest changes or improvements.
I kept the custom shebang plugin even though it references bublé because the build fails without it.
The tests are currently failing due to increased output sizes. I wanted to get some feedback before I update the snapshots. Should we look into reducing them before going forward with this?
A lot of inspiration in this PR was taken from @Andarist in #39. Thanks a lot for the pointers on where to look! Hope it's okay with you that I did it this way.
Fixes #25