Rename and add aliases for global module name. Can be applied after babel-plugin-transform-es2015-modules-umd to modify global module name (example below).
# With npm
$ npm install babel-plugin-rename-umd-globals --save-dev
# With yarn
$ yarn add babel-plugin-rename-assigned-properties --dev
Tested to work with Node >= 0.10
You need to define the rename mapping with plugin options. Just map of old names to new names (and their optional aliases).
Transform global.myModule = value
to global.MyM = value
{
"plugins": [
["rename-umd-globals", {
"myModule": "MyM"
}]
]
}
You can also add aliases for global module name by providing array. It will be transformed to chained assignments of global module name.
{
"plugins": [
["rename-umd-globals", {
"coolio": ["Coolio", "C", "ArtisLeonIveyJr"]
}]
]
}
require("babel-core").transform("code", {
plugins: [
["rename-umd-globals", {
"myModule": "MyM"
}]
]
});
It can be combined with babel-plugin-add-module-exports and babel-plugin-transform-es2015-modules-umd. Make sure to use the same plugin order as below!
{
"presets": ["es2015"],
"plugins": [
"add-module-exports",
"transform-es2015-modules-umd",
["rename-umd-globals", {
"myModule": "MyM"
}]
]
}
- Expects the global object to be named global. If your global scope object happens to be named differently, like root, then just use babel-plugin-rename-assigned-properties instead for arbitrary object property renaming.