use module id if available for umd global name - fixes #1166

This commit is contained in:
Sebastian McKenzie 2015-04-06 06:14:09 -07:00
parent c2776e63ae
commit 6b76f26ed8
4 changed files with 27 additions and 1 deletions

View File

@ -60,12 +60,17 @@ export default class UMDFormatter extends AMDFormatter {
var moduleName = this.getModuleName();
if (moduleName) defineArgs.unshift(t.literal(moduleName));
//
var globalArg = this.file.opts.basename;
if (moduleName) globalArg = moduleName;
globalArg = t.identifier(t.toIdentifier(globalArg));
var runner = util.template("umd-runner-body", {
AMD_ARGUMENTS: defineArgs,
COMMON_TEST: commonTests,
COMMON_ARGUMENTS: commonArgs,
BROWSER_ARGUMENTS: browserArgs,
GLOBAL_ARG: t.identifier(t.toIdentifier(this.file.opts.basename))
GLOBAL_ARG: globalArg
});
//

View File

@ -0,0 +1 @@
foobar();

View File

@ -0,0 +1,17 @@
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define("MyLib", ["exports"], factory);
} else if (typeof exports !== "undefined") {
factory(exports);
} else {
var mod = {
exports: {}
};
factory(mod.exports);
global.MyLib = mod.exports;
}
})(this, function (exports) {
"use strict";
foobar();
});

View File

@ -0,0 +1,3 @@
{
"moduleId": "MyLib"
}