ttypescript-browser-like-import-transformer

A custom transformer that can be used with ttypescript to transform ts imports to browser style imports


Project maintained by Jack-Works Hosted on GitHub Pages — Theme by mattgraham

Home > config > PluginConfigs > globalObject

PluginConfigs.globalObject property

When using UMD import, this option indicates what global object will be used to find the UMD variables.

Signature:

globalObject?: string

Example

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";