UMD modules (runtime only)

If we want to release a JavaScript library or framework, we will need to compile our TypeScript application into both CommonJS and AMD modules, as well as compile in a way that it can be used by developers who don't want to use a module loader.

The web development community has developed the following code snippet to help us to achieve UMD support:

(function (root, factory) { if (typeof exports === 'object') { // CommonJS module.exports = factory(require('b')); } else if (typeof define === 'function' && define.amd) { // AMD define(['b'], function (b) { return (root.returnExportsGlobal = factory(b)); }); } else { // Global Variables root.returnExportsGlobal = factory(root.b); } }(this, function (b) { // Your actual ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.