-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Cannot set core-js version for helper-only transformation in @babel/tranform-runtime
#9903
Comments
Hey @sodatea! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
As a workaround, you can use https://github.com/tleunen/babel-plugin-module-resolver to alias |
@sodatea I have been thinking about this issue today, and I think that the proper solution would be to transpile module.exports = {
overrides: [{
// Use exclude or include, but be sure not to transpile those two packages
exclude: ["@babel/runtime", "core-js"],
// Your normal config
presets: ["@babel/preset-env"],
plugins: ["@babel/plugin-transform-runtime"]
}, {
include: "@babel/runtime",
plugins: [
["@babel/plugin-transform-runtime", {
"helpers": false,
"corejs": 3
}]
]
}]
}; |
As recommended in babel/babel#9903. Get rid of the module-resolver plugin, may fix vuejs#3928. Seems to have fixed vuejs#4742 as well.
* refactor: use babel overrides to transpile babel runtime helpers As recommended in babel/babel#9903. Get rid of the module-resolver plugin, may fix #3928. Seems to have fixed #4742 as well. There may be a small breaking change: as we now use `excludes` & `includes`, babel requires `filename` option to be present (introduced in https://github.com/babel/babel/pull/10181/files). So users who call `babel.transformSync` directly may encounter an error. However, as we explicitly stated that this preset is only used for Vue CLI internally, I don't expect too many such use cases there. And the error messages are clear enough. Considering the benefits that this PR brings, I think it's an acceptable tradeoff. test: update tests for babel * test: fix windows tests * test: remove unused variables * fix: fix scope package paths on Windows * test: wait some time in router tests in case dom hasn't updated in time
I can't believe how hard was to find this. I found here from @vue/babel-preset-app source code. Basically all I want to do is to:
The problem is that the babel helpers themselves need polyfills when targeting IE 11 for example. Thanks to this issue & @vue/babel-preset-app source code I somehow managed to get this to work using following configuration:
PLEASE let me know if you know of a better way to achieve this. |
Your config looks fine to me: if a dependency ( There were a few problems when transpiling the As a personal note, I find this config more explicit: module.exports = {
sourceType: 'unambiguous',
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
corejs: 3
}]
],
overrides: [{
exclude: [/@babel[\/|\\\\]runtime/],
plugins: [
['@babel/plugin-transform-runtime', { version: '^7.8.4' }]
]
}]
}; It does the same thing as your config, but makes it explicit that Also, starting from v7.8.4 it's probably safe to transpile module.exports = {
sourceType: 'unambiguous',
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
corejs: 3
}]
],
plugins: [
['@babel/plugin-transform-runtime', { version: '^7.8.4' }]
]
}; |
@nicolo-ribaudo Alright, thanks for your insights! I also noticed that when setting |
However, if you don't use native ES modules it shouldn't make too much a difference anyway. |
Did some tests.. I'm using webpack 4. sourceType: 'unambiguous' + useEsModules: true seems to include both helpers/.js and helpers/esm/.js. So you should probably use |
@nicolo-ribaudo I did not have any dependencies other than babel/webpack related. See here https://github.com/micopiira/babel-webpack-test But using |
I'm closing this issue, since it's possible to transpile |
Feature Request
Is your feature request related to a problem? Please describe.
Basically we are trying to resolve this issue in @vue/babel-preset-app:
To be more specific, this item:
@babel/preset-env
with@babel/transform-runtime
, and the latter one is only used to do helper transformation.@babel/runtime-corejs2
. I know it's not the best solution but it's an acceptable compromise/tradeoff in practice.polyfills
option while still referring the helper functions to@babel/runtime-corejs2
.polyfills
option is removed because it is now the default behavior.helpers
to any other runtime package without introducing core-js polyfills along with it.Describe the solution you'd like
Bring back the
polyfills
option, allowing the user to opt-out it while still being able to specify a core-js version for helpers.Describe alternatives you've considered
N/A
Teachability, Documentation, Adoption, Migration Strategy
N/A
The text was updated successfully, but these errors were encountered: