2016-09-14 171 views
6

尝试对模块和目标有一些基本的了解。TypeScript编译选项:module vs target

我想知道模块之间的差异和目标编译典型tsconfig.json

 
{ 
    "compilerOptions": { 
     "module": "es6", 
     "sourceMap": true, 
     "target": "es6" 
    } 
} 

,如果我提供了以下选项,会发生什么选项:

模块:CommonJS的,目标:ES6

模块:ES6,目标:CommonJS的

模块:CommonJS的,目标:CommonJS的

+1

目标不能是commonjs。它只能是:'es3'(默认),'es5'或'es6'。你有没有读过[Compiler Options doc](https://www.typescriptlang.org/docs/handbook/compiler-options.html)? –

+0

Paleo的答案是一个重要的修正:[Documentation](https://www.typescriptlang.org/docs/handbook/compiler-options.html)实际上表示可以使用>>“ES6”和“ES2015”值** **定位时**“ES5”或更低**。<< – Peti29

回答

1

the documentation on the compiler options

--target

指定的ECMAScript目标版本: 'ES3'(默认值), 'ES5' 或 'ES6'。

--module

指定模块代码生成: '无', 'CommonJS的', 'AMD', '系统', 'UMD', 'ES6' 或 'ES2015'。

  • 只有'amd'和'system'可以和--outFile结合使用。
  • 当定位ES5或更低时,可能不会使用'es6'和'es2015'值。

参见:ES6 in depth: Modules

+3

下面是这个模块与目标混淆的更好的解释:https://stackoverflow.com/questions/41993811/understanding-target-and-module-in -tsconfig – Raghu