babel-plugin-transform-commonjs
babel-plugin-transform-commonjs copied to clipboard
Does this plugin will benefit from proposal top-level-await?
https://github.com/tc39/proposal-top-level-await
Once if babel implements this proposal. This plugin can replace require
to await import
to support require non-string-literal module ids?
Hi @shrinktofit I believe it does. We should remove the synchronousImport
option and instead opt to directly transpiling to a top-level await. This also has the potential to solve "top-level" conditional imports such as:
if (process.env.NODE_ENV === 'production') {
module.exports = require('react/prod');
}
else {
module.exports = require('react/test');
}
...converting to...
let _a;
if (process.env.NODE_ENV === 'production') {
_a = await import('react/prod');
}
else {
_a = await import('react/test');
}
export default _a;