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 > RewriteRulesURL

RewriteRulesURL interface

Rewrite module to another URL

Signature:

export interface RewriteRulesURL 

Example

{
    "type": "url",
    "withVersion": "https://cdn.example.com/$packageName$/v$version$""
    "noVersion": "https://cdn.example.com/$packageName$/latest"
}

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'

Output:

Filename: rules-url.js

// CompilerOptions: {"module":"ESNext"}
// PluginConfig: {"rules":{"type":"url","withVersion":"std:$packageName$@$version$","noVersion":"std:$packageName$"}}
console.log('Should run after all imports', a, b, c2, d, e, c2);
// Node style import
import a from "std:a";
import b, { c as c2, d } from "std:b";
import * as e from "std:c";
import "std:d";
const c = 1;
const x = 1;
export { x };
// Node style export
export { c, d } from "std:b";
export * as e from "std:c";

Properties

Property Type Description
noVersion string Rewrite to this URL if the transformer can’t read the version of the package
type ‘url’  
withVersion string Rewrite to this URL if the transformer can read the version of the package