Module imports generated by other Babel plugins are ignored
Elberet opened this issue · comments
When configured to do so, @babel/preset-env
can emit import
or require
statements at the top of each transpiled file to provide exactly those polyfills the code requires.
Example:
export default class Example {
buildMap() { return new Map().set("foo", "bar") }
}
Babel options:
let babelOptions = {
plugins: ["@babel/proposal-class-properties"],
presets: [
["@babel/env", {
targets: {
chrome: "64",
firefox: "58",
ie: "11"
},
modules: false,
useBuiltIns: "usage"
}],
["transform-ui5", {
autoConvertControllerClass: false,
moveControllerPropsToOnInit: true
}]
]
}
(Note: useBuiltIns: "usage"
is an experimental feature of @babel/preset-env
.)
Result:
import "core-js/modules/web.dom.iterable";
import "core-js/modules/es6.array.iterator";
import "core-js/modules/es6.string.iterator";
import "core-js/modules/es6.map";
// ...
sap.ui.define([], function () {
// ...
});
I have tried to reorder the "@babel/env"
and "transform-ui5"
presets in my Babel configuration, but babel-plugin-transform-modules-ui5
appears to be unable to transform the imports generated by other plugins.
I've started to fix this on branch fix/move-module-transform-out-of-program-enter-visitor
. It's a pretty big change that I've been putting off for awhile. The unit tests are all good and I spot checked it in my example app, but I need to check it against some real world apps.
How far along is that branch? I could run some tests with the app we're building right now (can't release the sources, unfortunately 🙁), but it'll take a few days...
Testing of this went well so I pushed it as v7.0.0.rc6.
v7 release coming soon. I just want to get all the options where I think makes sense.