-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix($core): include polyfills correctly (close #1168) #2317
Conversation
included in the build output (fix vuejs#1168)
Great thanks for your investigation! This PR indeed fix the four extra polyfills! 👍 However, some other polyfills are still not included correctly. E.g. |
Co-Authored-By: meteorlxy <meteor.lxy@foxmail.com>
I was so focused on getting the 4 polyfills included that I didn't look closely enough at the others. I will look into it. |
I think I've got it fixed now. The problemWhen transpiling certain syntax, babel injects helper code that uses APIs (e.g. vue-cliI don't see this problem in a "hello world" app generated by vue-cli so I looked at how it handles the issue. Apps generated by vue-cli have a check that includes My changeAdded same check as seen in the vue-cli code. Long term fixLooks like babel project is preparing some changes that should make this workaround unnecessary: https://github.com/babel/babel/projects/12 edit: I've also got a VM set up now so I can test in IE11 and Edge. I updated my original PR comment with the versions. |
@psalaets Really appreciate it! |
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
Co-Authored-By: meteorlxy <meteor.lxy@foxmail.com>
Summary
What kind of change does this PR introduce? (check at least one)
If changing the UI of default theme, please provide the before/after screenshot:
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
fix #xxx[,#xxx]
, where "xxx" is the issue number)You have tested in the following browsers: (Providing a detailed version will be better.)
If adding a new feature, the PR's description includes:
To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.
Other information:
This change passes the list of entry files into the options of
@vue/babel-preset-app
.I spent some time looking at #1168 and this is what I found out:
@vue/babel-preset-app
invokes@babel/preset-env
with itsuseBuiltIns: 'usage'
option, which means polyfills are only added if the user's code makes use of those language features.But,
@vue/babel-preset-app
will try to auto-include 4 specific polyfills, if the target env needs them. These polyfills for language features needed by libraries that are usually used with vue (e.g. vuex, vue-router). By default,@babel/preset-env
withuseBuiltIns: usage
doesn't look at dependencies, so auto-including the polyfills is a way to ensure they're available in a vue app.The 4 polyfills are:
es.array.iterator
es.promise
es.object.assign
es.promise.finally
In
@vue/babel-preset-app
, there is a private babel plugin calledpolyfillsPlugin
which adds the polyfills to the top of the files specified by the "entryFiles" option. Due to the way vuepress currently invokes@vue/babel-preset-app
, no entry files are specified so the auto-included polyfills never make it into the bundle.