npm install ts-global-module-loader
For code that generated from Typescript that looks like that:
var services;
(function (services) {
var Foo = (function () {
function Foo() {
}
return Foo;
}());
services.Foo = Foo;
})(services || (services = {}));
require("ts-global-module-loader?./file.js");
will modify the code file's source to:
var services = window["services"];
(function (services) {
var Foo = (function () {
function Foo() {
}
return Foo;
}());
services.Foo = Foo;
})(services || (services = {}));
window["services"] = (services);
Inspired by https://github.com/webpack/exports-loader;