Closed
Description
Describe the bug
globals
in the module
option of type: umd
is there to remap the module name asigned to global
. That's how it is used in babel @babel/plugin-transform-modules-umd
{
"plugins": [
[
"@babel/plugin-transform-modules-umd",
{
"globals": {
"es6-promise": "Promise"
}
}
]
]
}
exposing global.Promise
rather than the default global.es6Promise
.
swc seeming to go with global.fileName
. Which normally a config like:
{
"$schema": "http://json.schemastore.org/swcrc",
"module": {
"type": "umd",
"globals": {
"index": "HeroJs"
}
},
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dts": true,
"dynamicImport": true
},
"baseUrl": ".",
"paths": {
"/*": ["./src/*"]
}
},
"sourceMaps": true
}
Should replace the global.index
with global.HeroJs
for an index.js
module file. That's not happening:
The output still went as:
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.index = {});
Full output file:
(function(global, factory) {
if (typeof module === "object" && typeof module.exports === "object") factory(exports);
else if (typeof define === "function" && define.amd) define([
"exports"
], factory);
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.index = {});
})(this, function(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
Class1: function() {
return Class1;
},
Class2: function() {
return Class2;
},
Hero: function() {
return Hero;
}
});
function _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _classCallCheck(instance, Constructor) {
if (!_instanceof(instance, Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
var Class1 = function() {
"use strict";
function Class1() {
_classCallCheck(this, Class1);
}
var _proto = Class1.prototype;
_proto.go = function go() {
return 1;
};
return Class1;
}();
var Class2 = function() {
"use strict";
function Class2() {
_classCallCheck(this, Class2);
}
var _proto = Class2.prototype;
_proto.start = function start() {
return 1;
};
return Class2;
}();
var Hero = function Hero() {
"use strict";
_classCallCheck(this, Hero);
this.c1 = new Class1();
this.c2 = new Class2();
};
});
//# sourceMappingURL=index.swc.umd.js.map
Input code
File name index.js
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
var Class1 = function() {
"use strict";
function Class1() {
_classCallCheck(this, Class1);
}
var _proto = Class1.prototype;
_proto.go = function go() {
return 1;
};
return Class1;
}();
var Class2 = function() {
"use strict";
function Class2() {
_classCallCheck(this, Class2);
}
var _proto = Class2.prototype;
_proto.start = function start() {
return 1;
};
return Class2;
}();
var Hero = function Hero() {
"use strict";
_classCallCheck(this, Hero);
this.c1 = new Class1();
this.c2 = new Class2();
};
export { Class1 as Class1 };
export { Class2 as Class2 };
export { Hero as Hero };
Config
{
"$schema": "http://json.schemastore.org/swcrc",
"module": {
"type": "umd",
"globals": {
"index": "HeroJs"
}
},
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dts": true,
"dynamicImport": true
},
"baseUrl": ".",
"paths": {
"/*": ["./src/*"]
}
},
"sourceMaps": true
}
Playground link
Expected behavior
globs to work like with babel and allow renaming (mapping).
Actual behavior
globals not working.
Version
"@swc/cli": "^0.1.57", "@swc/core": "^1.3.23"
Additional context
No response