Modular Libraries

Modular Libraries

Some libraries only work in a module loader environment. For example, because express only works in Node.js and must be loaded using the CommonJS require function.

ECMAScript 2015 (also known as ES2015, ECMAScript 6, and ES6), CommonJS, and RequireJS have similar notions of importing a module. In JavaScript CommonJS (Node.js), for example, you would write

var fs = require("fs");

In TypeScript or ES6, the import keyword serves the same purpose:

import fs = require("fs");

You’ll typically see modular libraries include one of these lines in their documentation:

var someLib = require('someLib');

or

define(..., ['someLib'], function(someLib) {

});

As with global modules, you might see these examples in the documentation of a UMD module, so be sure to check the code or documentation.

doc_TypeScript
2016-10-04 19:25:24
Comments
Leave a Comment

Please login to continue.