【发布时间】:2019-08-23 14:29:22
【问题描述】:
我正在尝试了解 typescript 模块编译器选项。
我浏览了打字稿文档 - docs
它说模块选项是Specify module code generation。
这是什么意思?
是否意味着如果我将模块选项设置为commonjs,那么编译器会将代码编译为commonjs?但是我们有像esnext, es16 这样的选项。经过Docs: Difference between esnext, es6, es2015 module targets之后,我明白了import() expressions are understood in esnext。无论如何,编译器的目的是将代码编译成浏览器可理解的语法(commonjs)。因此将代码编译为给定的模块类型没有意义。
这是否意味着您提供的模块类型告诉编译器代码是用什么语法编写的?意味着它必须从哪个代码编译到commonjs?但是我们有模块类型commonjs,它经常使用,但我们几乎从不使用纯 commonjs 语法编写代码。
what is the purpose of tsconfig.json?stackoverflow 回答说module specifies module manager。我不明白那是什么意思。
我也经历过Understanding “target” and “module” in tsconfig 和tsconfig module options - does 'System' refer to SystemJS?。
这些似乎都不能正确回答我的问题。
tsconfig.json
{
"compilerOptions: {
"module": "esnext"
}
}
【问题讨论】:
标签: javascript typescript compilation commonjs tsconfig