JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 42
  • Score
    100M100P100Q62739F
  • License MIT

A babel plugin that exposes ES6 modules to global variables.

Package Exports

  • babel-plugin-globals

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-globals) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

babel-plugin-globals

A babel plugin that exposes ES6 modules to global variables.

##Usage This is a babel plugin that converts ES6 modules into global variables. To use it, just add it to your package.json and pass it as a plugin when calling babel:

{
  "plugins": [
    ["globals", {
      "globalName": 'myGlobal'
    }]
  ],
  "filename": filename
}
// Modules will be available at this.myGlobal.

API

This plugin requires passing the following plugin/babel options (besides adding the plugin):

Plugin options

globalName {string|!function()}

The name of the global variable that the modules should be exported to.

Default exports will be exported as <globalName>.<filename> whilst named exports will be exported as <globalName>Named.<fileName>.<exportName>.

globalName can also receive a function that returns the whole variable path for each export (e.g. (state, filePath, name, isWildcard) => 'this.MyModule.Views' + (name ? '.' + name : ''))

Babel options

filename {string}

This is an optional existing babel option, but is required for this plugin, since the plugin uses the file name to decide the name of the keys that will be exported in the global variable.