-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
refactor!: esbuild 0.11 upgrade, remove dynamic-import-polyfill #2976
Conversation
I don't add |
There are issues with dynamic imports after upgrading
Thanks for the PR @ludofischer. We didn't update until now because there were breaking changes in esbuild 0.10 that affect Vite. It looks like the test suite cannot detect some issues that appear after bumping esbuild to 0.11.10. You can |
Seems it's caused by the Related evanw/esbuild#1146, evanw/esbuild#1084 (maybe @evanw can help) More context: Vite uses a dynamic import polyfill for browsers that don't support it natively. |
According to Microsoft, legacy Edge has been EOL since last month on March 9th, 2021 and the new Edge was added during a security update on April 13th, 2021, which includes the removal of legacy Edge. |
Nice timing, changing it to |
@GrygrFlzr @egoist were you able to avoid the dynamic import issue in a vitesse app when by moving to |
@patak-js Tried it out and cross-referenced the // handle special build targets
if (resolved.target === 'modules') {
// https://caniuse.com/usage-table
// https://caniuse.com/es6-module
// https://caniuse.com/es6-module-dynamic-import
// https://github.com/evanw/esbuild/blob/d354bbb/internal/compat/js_table.go#L87
resolved.target = [
'es2019',
// previously: edge18
'edge79',
// previously: firefox60
'firefox67',
// previously: chrome61
'chrome63',
// previously: safari11
'safari11.1'
]
} else if (resolved.target === 'esnext' && resolved.minify !== 'esbuild') {
// esnext + terser: limit to es2019 so it can be minified by terser
resolved.target = 'es2019'
} However, with the import polyfill we'd actually support earlier versions as well. It's a shame we can't just pass "chromeX,safariX,...,DynamicImport" to esbuild... |
Do I understand correctly that this change moves support for some browsers out of vanilla vite and to the legacy plugin?
|
It depends on what the real feature diff is between the changed browser versions. We need to look at the esbuild compatibility table and see what other features are considered "supported" by esbuild due to the change. If the only significant change is dynamic imports, then we'd retain the same supported versions due to the default polyfill. If not, then we have two options, presumably:
|
0b8c0f6
to
3f24756
Compare
I've given it a shot to see what updating the browser targets and removing the dynamic import polyfill looks like.
I would not like the legacy plugin turning on automatically, as I would find the build time and output change jarring. |
3f24756
to
d5c6d4b
Compare
As a counter-point: there have been some important improvements since the current esbuild version, especially [email protected], which should improve compatibility with old packages or non-standard packages significantly. |
Thanks for looking into this @nihalgonsalves! We really need to move to esbuild 0.11.x (and forward). There are many issues that are going to be solved after this. I think that bumping the browser versions for this is ok, we don't have many options. Note: There have already been other releases where we needed to bump the browser versions, see #2566 |
@patak-js yup, I gave it some more thought, and I think that we could update the Browser Compatibility section to refer to a browserslist query instead. # for example:
$ npx browserslist "defaults and supports es6-module, not opera > 0, not samsung > 0, not and_qq > 0"
# returns this:
and_chr 90
and_ff 87
android 90
chrome 90
chrome 89
chrome 88
chrome 87
edge 90
edge 89
edge 88
firefox 88
firefox 87
firefox 86
firefox 78
ios_saf 14.5
ios_saf 14.0-14.4
ios_saf 13.4-13.7
safari 14
safari 13.1 which would let us use a target of |
@nihalgonsalves but the dynamic import polyfill gives us a wider range of browsers than that query, no? |
Yeah, it's just an example. I mean that we should document some range instead of exact browser versions in the README. Though the fact that the default query (
is probably a sign that we don't really need to support earlier versions. (The query is equivalent to |
I think that is a good idea. Is there a way to add the dynamic import polyfill coverage to a browserlists query? |
I don't think so. But by usage, browsers that don't support dynamic imports are actually a very minuscule percentage now, that's the argument @ludofischer and I were trying to make - we could just drop the polyfill. @patak-js A better way to illustrate it: |
f851eb3
to
f5e859c
Compare
@ludofischer we discussed with Evan and we can move forward with the approach proposed by @nihalgonsalves. 0.2% of browsers don't justify the complexity of the dynamic import polyfill (see #1512 for an example of an issue with the plugin). And on top of that, as @nihalgonsalves explained, being able to specify the browser query as a features query instead of hard numbers is better for our users, and to avoid issues if esbuild changes again. Technically, this change would require a major change but the affected browser set is so small that we will need to do a tradeoff here. This change is going to be released in the next minor as Vite v2.3.0 @ludofischer could you also update the docs at: https://vitejs.dev/guide/#browser-support and here https://vitejs.dev/guide/build.html#browser-compatibility? We can simplify this because pointing to full es6-module support. And add the new dynamic query
Also, we should remove the application of the dynamic import polyfill by default but we should leave the option so we don't error out because of its presence in Thanks again for the work on this PR. |
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.
See #2976 (comment)
Don't you mean |
I believe both are irrelevant, as they don't change the output of the defaults query. We could keep it simple: ## Browser Compatibility
-The production bundle assumes a baseline support for modern JavaScript. By default, all code is transpiled targeting [browsers with native ESM script tag support](https://caniuse.com/es6-module):
+The production bundle assumes a baseline support for modern JavaScript. Vite targets [browserslist](https://github.com/browserslist/browserslist)'s `defaults` query.
+
+This is a moving target based current usage. Run `npx browserslist` to see the current versions.
-- Chrome >=61
-- Firefox >=60
-- Safari >=11
-- Edge >=16
-A lightweight [dynamic import polyfill](https://github.com/GoogleChromeLabs/dynamic-import-polyfill) is also automatically injected.
You can specify custom targets via the [`build.target` config option](/config/#build-target), where the lowest target is `es2015`.
Note that by default, Vite only handles syntax transforms and **does not cover polyfills by default**. You can check out [Polyfill.io](https://polyfill.io/v3/) which is a service that automatically generates polyfill bundles based on the user's browser UserAgent string.
Legacy browsers can be supported via [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy), which will automatically generate legacy chunks and corresponding ES language feature polyfills. The legacy chunks are conditionally loaded only in browsers that do not have native ESM support. We could still document the current versions, but the docs would go out of date constantly. |
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.
LGTM
@ludofischer looks like there are conflicts with main, seems that we can merge this once they are resolved 👍🏼 |
BREAKING CHANGE: update modules target to avoid mixing `import` and `require()` BREAKING CHANGE: remove dynamic import polyfill docs: update browser support docs
532e2ed
fea6590
to
532e2ed
Compare
I've rebased on |
Thanks a lot for the work on this PR 🙌🏼 |
This was left by vitejs#2976.
Description
Upgrade
esbuild
to the latest version, so vite stays in sync with the experience users get when they installesbuild
standalone (e.g.npm install esbuild
).Additional context
There are some interesting bug fixes for JavaScript transpilation (for example evanw/esbuild#1131, evanw/esbuild#977, evanw/esbuild#959, evanw/esbuild#1066), but the upgrade should be relatively safe as most esbuild changes only affect chunking and code splitting (while vite uses rollup for that).
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).