und

undefaultify

Post-processor for ES6-to-UMD transpiled modules, and you want to export "default" directly

Showing:

Popularity

Downloads/wk

1

Maintenance

No Maintenance Data Available

Package

Dependencies

0

Size (min+gzip)

0.4KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Deprecated!
Using this package is NOT recommended. It is no longer maintained.

Readme

undefaultify

Post-processor for UMD bundles if source was ES6 Modules, and you want to export default directly.

For instance, transpiling ES6 code to CommonJS and then use Browserify in standalone, results in such a UMD bundle.

Why

When transpiling ES6 code to CommonJS, the export value is assigned to the default property. This is a nice solution for interoperability between various module systems, but I don't like my library consumers to require an unexpected require('mylib').default (either in CommonJS or AMD).

What

It rewrites the prelude for "standalone" UMD bundles, so it exports the default property of the exported object instead of the exported object itself. For consumers of your library:

// Before
var lib = require('lib').default;

// After
var lib = require('lib');

How

It's horrible. With a regular expression, the source code is modified:

// Before
!function(e){})
    
// After
!function(_e) {
    function e() {
        return _e()["default"]
    }
});

The definition function e is renamed to _e and returns the default property of the original return value of e().

And

You can also tell it to rename the exported name. I wasn't able to export as "_" or "$" with Browserify directly, so included it here. This is pretty rare, though.

Example usage

browserify es6/entry.js --transform 6to5-browserify --standalone mylib | undefaultify > dist/lib.js

browserify es6/entry.js --transform es6ify --standalone mylib | undefaultify mylib _ > dist/lib.js

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100