-
Notifications
You must be signed in to change notification settings - Fork 821
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
chore: add esm2015 entry for web apps aiming at modern browsers #2556
chore: add esm2015 entry for web apps aiming at modern browsers #2556
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2556 +/- ##
==========================================
- Coverage 93.36% 93.31% -0.06%
==========================================
Files 131 131
Lines 4932 4923 -9
Branches 1078 1078
==========================================
- Hits 4605 4594 -11
- Misses 327 329 +2
|
05d08e4
to
94b7521
Compare
I'm curious about the entry point "esm2015". Is the entry point name "esm2015" widely adopted with any tools? For shipping a new build variant, I'm wondering that what if people would like to perform tree-shaking but don't need to transpile to lower ECMAScript versions? Should we ship more entry points and build variants like "esm2016", or "esm2017"? Would it be better if we ship a new ESM build variant that is merely striped typescript annotations and leaves all other syntaxes as is? |
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 looks nice and promising, definitely nice improvement. Perhaps @MSNev can be interested in this too ?
I could not find the convention of the field "esm2015" of package.json. For me who would like to enable esm2015 entry point needs to know this new rule and set "esm2015" into the mainFields. ESM2015 which is widely supported by many modern browsers and covers most syntax. Would it be better if just change the entry point "module" to use esm2015? |
That's been discussed at #2472 (comment) recently and we concluded that we are not going to ship modern javascript on the "module" entrypoint in the near future. |
I'll leave this to @obecny and @MSNev who have more browser experience (and this one affects bundle size so Nev will be happy) but generally these changes look ok to me and I have no real objections. My only concern is that shipping more and more builds in the same package bloats the package size, but I don't think it's a real problem quite yet. |
I wouldn't mind to have extra entry point. 1st - it doesn't harm or is causing any regression. 2nd - it gives some benefit for those eager to use it. So in general "yes" from me |
I'm actually not too fussed on this (I can have it either way). Avoiding polyfill's is always a good thing for size savings and this change (I think) is really only helps users that are consuming the pre-built *.js. And how many people are really only targeting esm2015 for not just this component but for their entire app?? If we deployed to a CDN then I say absolutely (for those users that can target only modern browser) but as we dont I'm not against it either as there will be some percentage (unknown) that would find this useful. But I think generally, anyone using would probably pick and choose the components they want and their packager will take care of tree shaking... |
Separate resolve field definitely a good way to bypass the issue of module field & babel ignore node_modules inertia, tho it not being a standard field (hence having to configure your bundler to use esm2015 as entry field as shown in screenshots) does mean that the amount of users who end up using this is quite low (since you'd have to discover this option being available - either discovering it in package.json and wondering what it is or finding this PR). Maintenance burden is probably low enough that cost:benefit(ing users) ratio doesn't really matter, but there's no documentation updates in this PR that explain a) this option is available b) how to use it Worth considering: Why stop at just target: es6? If there is an option for modern-er code that the user has to explicitly opt into, then there's already enough intent that could consider target (There ofc may be tooling limitations, I don't know if vite supports transpiling dependencies as it only uses babel for legacy bundles that you only get via a plugin) While I can't find a good list of what gets transformed with different typescript targets, compat-table has pretty good list of language features by es2016+ version. Out of these I've seen for sure in otel codebase:
|
I'm supportive of targeting esnext. |
I would be supportive of targeting esnext as an opt-in |
@echoontheway can i get you to fix the conflicts so this can be merged? |
The new entry point (either "esm2015" or "esnext") is already an opt-in option as users have to explicitly set the entry point to get it recognized by the bundler. Can you elaborate on this? |
I was just voicing my support for the PR and making it clear to readers that it is opt-in for those that don't know. |
@echoontheway can you resolve the conflicts? |
94b7521
to
36705eb
Compare
resolved, sorry for late. |
Which problem is this PR solving?
Fixes
relevant issue: ESM build targets ES5 resulting in polyfills for await #2471
relevant issue: Pure annotation in downlevel emits microsoft/TypeScript#13721
Short description of the changes
Type of change
How Has This Been Tested?
Enhancements above is tested by a simplified web app.
the tool to pack the web app is vite, the tool to analyze bundle size is rollup-plugin-visualizer
use esm2015 entry point
npm run build
133KB, details
use esm entry point
npm run build
186KB, details