Closed
Description
Suggestion
π Search Terms
- UMD output option for single fileΒ #6380
- umd module compiler option doesn't have a fallback for global namespace.Β #8436
- Completions are low-quality for UMD modules without typingsΒ #20565
- Error when augmenting UMD moduleΒ #13565
- Proposal: Bundling TS module type definitionsΒ #4433
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
ts is support UMD module , but not UMD bundle. Vue
,React
and other package is using UMD and webpack to release their js base packages, but we come to typescript , you must need webpack and rewrite types for browse base code(sync load with <script>
tag)
and follow feature to implement this goalοΌ
- declaration merge eg. bundle declaration files
entryfile
in tsconfig.jsonumdModuleName
in tsconfig.json , this will pack every exported variable inentryfile
to this namespace- dependency bundle and dependency exclude (preload dependency and self-contained dependency)
(outFile can do this)umdBundle
of boolean in tsconfig.json- declaration for
umdModuleName
, ability to generate and also be used by typescript as well ( global variable access and type consume ) see code below
// lib.d.ts
export declare class Foo{
sayHello():string;
createNewFoo():Foo;
}
declare global
{
declare let foo:Foo;
}
// main.ts none module
foo.sayHellow
let myFoo:Foo = null ; // error, where is Foo class ? import Foo from "lib" , will cause exports.__esModule == true
// and break `<script>` load in browse; <reference path /> won't load this type
if(true) // somcondition
{
myFoo = foo.createNewFoo();
}
π» Use Cases
generate a umd bundle and can be use either browse <script>
and other loader (eg. webpack, amd,CommonJS)