TypeScript 编译选项:模块与目标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39493003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeScript Compile Options: module vs target
提问by user203687
Trying to have some basic understanding about module and target.
试图对模块和目标有一些基本的了解。
I would like to know the difference between module and target compile options in a typical tsconfig.json
我想知道典型 tsconfig.json 中模块和目标编译选项之间的区别
{ "compilerOptions": { "module": "es6", "sourceMap": true, "target": "es6" } }
What happens if I provide the following options:
如果我提供以下选项会发生什么:
module: commonjs, target: es6
模块:commonjs,目标:es6
module: es6, target: commonjs
模块:es6,目标:commonjs
module: commonjs, target: commonjs
模块:commonjs,目标:commonjs
采纳答案by Paleo
A more detailed explanation is here : Understanding "target" and "module" in tsconfig
更详细的解释在这里:了解 tsconfig 中的“目标”和“模块”
See also: Understanding "target" and "module" in tsconfig.
另请参阅:了解 tsconfig 中的“目标”和“模块”。
Here is a quote from the documentation on compiler options:
这是编译器选项文档中的引述:
--target
Specify ECMAScript target version: 'es3' (default), 'es5', or 'es6'.
--module
Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', or 'es2015'.
- Only 'amd' and 'system' can be used in conjunction with --outFile.
- 'es6' and 'es2015' values may be used when targeting ES5 or lower.
- 目标
指定 ECMAScript 目标版本:“es3”(默认)、“es5”或“es6”。
- 模块
指定模块代码生成:“none”、“commonjs”、“amd”、“system”、“umd”、“es6”或“es2015”。
- 只有 'amd' 和 'system' 可以与 --outFile 结合使用。
- 'es6' 和 'es2015' 值可用于 ES5 或更低版本。
回答by motss
There are 2 different things. --target
simply means which version of ECMAScriot you're using to code. --module
simply means which module system you're using such as commonjs
for Node or ES module for all that supports it and what not.
有2种不同的东西。--target
只是意味着您使用哪个版本的 ECMAScriot 进行编码。--module
只是意味着您正在使用哪个模块系统,例如commonjs
Node 或 ES 模块,用于支持它的所有模块以及不支持它的模块。