1. babel-plugin-rename-umd-globals
Renames the module's global variable and adds optional global aliases
babel-plugin-rename-umd-globals
Package: babel-plugin-rename-umd-globals
Created by: jamonkko
Last modified: Mon, 13 Jun 2022 04:03:14 GMT
Version: 1.0.0
License: MIT
Downloads: 242
Repository: https://github.com/jamonkko/babel-plugin-rename-umd-globals

Install

npm install babel-plugin-rename-umd-globals
yarn add babel-plugin-rename-umd-globals

Build Status
Coverage Status
npm version
npm downloads
Dependency Status
devDependency Status
JavaScript Style Guide
Sponsored by Leonidas

babel-plugin-rename-umd-globals

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).

Installation

 # 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

Usage

Options

You need to define the rename mapping with plugin options. Just map of old names to new names (and their optional aliases).

Example via .babelrc

Transform global.myModule = value to global.MyM = value

 {
  "plugins": [
    ["rename-umd-globals", {
      "myModule": "MyM"
    }]
  ]
}

More examples via .babelrc

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"]
    }]
  ]
}

Via Node API

 require("babel-core").transform("code", {
  plugins: [
    ["rename-umd-globals", {
      "myModule": "MyM"
    }]
  ]
});

Together with other umd plugins

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"
    }]
  ]
}

Caveats

  • 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.

Sponsors

Leonidas

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin