Difference between module type in tsconfig.json

In tsconfig.json

{ "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false } } 

I can not understand the difference between the following types of module :

"commonjs", "amd", "umd", "system", "es6", "es2015", "none"

Question: What value should be used and when to use it?

+5
source share
1 answer

CommonJS template (or nodejs):

 var someOtherFunction = require('./someOtherFunction.js'); exports.add = function() { var sum = 0, i = 0, args = arguments, l = args.length; while (i < l) { sum += args[i++]; } return sum; } 

ES6 circuit:

 import someOtherFunction from './someOtherFunction.js'; export function add() { var sum = 0, i = 0, args = arguments, l = args.length; while (i < l) { sum += args[i++]; } return sum; } 

AMD Model:

 define(['someOtherFunction'], function () { return function () { var sum = 0, i = 0, args = arguments, l = args.length; while (i < l) { sum += args[i++]; } return sum; }; }); 

The definition of an asynchronous module (AMD) is the most popular for client code, and node.js modules (an extension for CommonJS Modules / 1.1) is a leading example on the server side of the environments.

Universal Module Definition (** UMD ) ** is a set of template recipes that try to overcome the differences between AMD and node.js, which allows engineers to create their code bases in one format rather than the author in both formats or convert to another format on assembly stage.

ES5 is the usual javascript you saw.

You are using ES6 for Angular2, also known as ECMAScript 2015.

+2
source

Source: https://habr.com/ru/post/1261893/


All Articles