A custom transformer that can be used with ttypescript to transform ts imports to browser style imports
Home > config > RewriteRulesSimple
Predefined rewrite rules
Signature:
export type RewriteRulesSimple = 'snowpack' | 'umd' | 'unpkg' | 'pikacdn'
snowpack: Rewrite to snowpack (/web_modules) (deprecated: should use import map)
umd: Rewrite to UMD import
unpkg: Rewrite to unpkg (a CDN)
pikacdn: Rewrite to pikacdn (another CDN)
Source code:
Filename: rules-default.ts
console.log('Should run after all imports', a, b, c2, d, e, c2)
// Node style import
import a from 'a'
import b, { c as c2, d } from 'b'
import * as e from 'c'
import 'd'
const c = 1
const x = 1
export { x }
// Node style export
export { c, d } from 'b'
export * as e from 'c'
Outputs:
Filename: rules-umd.js
// CompilerOptions: {"module":"ESNext"}
// PluginConfig: {"rules":"umd"}
const a = __UMDBindCheck(globalThis["a"], ["default"], "a", "globalThis.a", false).default;
const b = __UMDBindCheck(globalThis["b"], ["default"], "b", "globalThis.b", false).default;
const { c: c2, d } = __UMDBindCheck(globalThis["b"], ["c", "d"], "b", "globalThis.b", false);
const e = __UMDBindCheck(globalThis["c"], [], "c", "globalThis.c", false);
const { c_1, d_1 } = __UMDBindCheck(globalThis["b"], ["c", "d"], "b", "globalThis.b", false);
export { c_1 as c, d_1 as d };
const e_1 = __UMDBindCheck(globalThis["c"], [], "c", "globalThis.c", false);
export { e_1 as e };
console.log('Should run after all imports', a, b, c2, d, e, c2);
"import \"d\" is eliminated because it expected to have no side effects in UMD transform.";
const c = 1;
const x = 1;
export { x };
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: rules-pikacdn.js
// CompilerOptions: {"module":"ESNext"}
// PluginConfig: {"rules":"pikacdn"}
console.log('Should run after all imports', a, b, c2, d, e, c2);
// Node style import
import a from "https://cdn.pika.dev/a";
import b, { c as c2, d } from "https://cdn.pika.dev/b";
import * as e from "https://cdn.pika.dev/c";
import "https://cdn.pika.dev/d";
const c = 1;
const x = 1;
export { x };
// Node style export
export { c, d } from "https://cdn.pika.dev/b";
export * as e from "https://cdn.pika.dev/c";
Filename: rules-snowpack.js
// CompilerOptions: {"module":"ESNext"}
// PluginConfig: {"rules":"snowpack"}
console.log('Should run after all imports', a, b, c2, d, e, c2);
// Node style import
import a from "/web_modules/a.js";
import b, { c as c2, d } from "/web_modules/b.js";
import * as e from "/web_modules/c.js";
import "/web_modules/d.js";
const c = 1;
const x = 1;
export { x };
// Node style export
export { c, d } from "/web_modules/b.js";
export * as e from "/web_modules/c.js";
Filename: rules-unpkg.js
// CompilerOptions: {"module":"ESNext"}
// PluginConfig: {"rules":"unpkg"}
console.log('Should run after all imports', a, b, c2, d, e, c2);
// Node style import
import a from "https://unpkg.com/a?module";
import b, { c as c2, d } from "https://unpkg.com/b?module";
import * as e from "https://unpkg.com/c?module";
import "https://unpkg.com/d?module";
const c = 1;
const x = 1;
export { x };
// Node style export
export { c, d } from "https://unpkg.com/b?module";
export * as e from "https://unpkg.com/c?module";