A custom transformer that can be used with ttypescript to transform ts imports to browser style imports
Home > config > PluginConfigs > globalObject
When using UMD import, this option indicates what global object will be used to find the UMD variables.
Signature:
globalObject?: string
“globalThis” in all modern ES platforms.
“window” or “self” in browsers.
“global” in NodeJS.
Source:
Filename: globalObject-default.ts
/// {}
import R from 'react'
console.log(R)
Outputs:
Filename: globalObject-undefined.js
// CompilerOptions: {"module":"ESNext"}
// PluginConfig: {}
const R = __UMDBindCheck(globalThis["React"], ["default"], "react", "globalThis.React", false).default;
console.log(R);
import { __UMDBindCheck as __UMDBindCheck } from "https://cdn.jsdelivr.net/npm/@magic-works/ttypescript-browser-like-import-transformer@2.1.2/es/ttsclib.min.js";
Filename: globalObject-string.js
// CompilerOptions: {"module":"ESNext"}
// PluginConfig: {"globalObject":"global"}
const R = __UMDBindCheck(global["React"], ["default"], "react", "global.React", false).default;
console.log(R);
import { __UMDBindCheck as __UMDBindCheck } from "https://cdn.jsdelivr.net/npm/@magic-works/ttypescript-browser-like-import-transformer@2.1.2/es/ttsclib.min.js";
Filename: globalObject-window.js
// CompilerOptions: {"module":"ESNext"}
// PluginConfig: {"globalObject":"window"}
const R = __UMDBindCheck(window["React"], ["default"], "react", "window.React", false).default;
console.log(R);
import { __UMDBindCheck as __UMDBindCheck } from "https://cdn.jsdelivr.net/npm/@magic-works/ttypescript-browser-like-import-transformer@2.1.2/es/ttsclib.min.js";