es6-module-transpiler-globals-formatter
ES6 Module Transpiler extension to output exported content as globals.
Install
$ npm install --save-dev es6-module-transpiler-globals-formatter
Usage
Just set the formatter
key to an instance of GlobalFormatter
.
Remember to set the global name to be used first though.
var GlobalsFormatter = ;var transpiler = ;var Container = transpilerContainer;var FileResolver = transpilerFileResolver; var container = resolvers: 'lib/' formatter: globalName: 'myGlobal'; container;container;
Output
The output file is basically the same delivered by the original BundleFormatter
, with the addition of global assignments for exported values at the end.
All exported values will be added inside a single object in the global scope with the name specified by the globalName
configuration option. The keys of this object will be the names of the variables that were exported, so note that there may be conflicts.
For example, say we have the following export declarations:
// foo/foo.jsvar foo = 1;; // foo/bar.js; var bar = foo + 1;;
The output bundle file's contents will be similar to the following (assuming exportedValues
as the given global name):
{ "use strict"; var foo$foo$$foo = 1; foo$foo$$default = foo$foo$$foo; var foo$foo$$bar = foo$foo$$foo + 1; thisexportedValues = thisexportedValues || {}; thisexportedValuesfoo = foo$foo$$foo; thisexportedValuesbar = foo$foo$$bar;};