Skip to content

Optional export for UMD standalone #5

@bisubus

Description

@bisubus

This would be beneficial because it tends to pollute globals even when it is unncessary.

The possible case is Angular module, e.g.

(function(__root, __factory) {
    if (typeof define === "function" && define.amd) {
        define("module-name", ["angular"], __factory);
    } else if (typeof exports === "object") {
        module.exports = __factory(require("angular"));
    } else {
        __root["module-name"] = __factory(angular);}
})(this, (function(__small$_mod_0) {

var exports = {};
...
exports = "moduleName";
return exports;
}))

The wide-spread convention for modular Angular workflow is

angular.module('appName', [require('module-name')]);
// instead of
// require('module-name');
// angular.module('appName', ['moduleName']);

So exported string is used only in the context of require or import, and __root["module-name"] = could be safely omitted if exportPackage.standalone === ''.

The checks for exportPackage.amd and exportPackage.commonjs could be added for consistency as well, but I see no possible use for that.

Can we do that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions