我试图理解typescript模块编译器选项.
我浏览了typescript文档-docs
这是什么意思?
这是否意味着如果我将模块选项设为commonjs
,那么编译器会将代码编译为commonjs?但我们有esnext, es16
这样的 Select .在我读完Docs: Difference between esnext, es6, es2015 module targets分后,我明白了import() expressions are understood in esnext
分.无论如何,编译器的目的是将代码编译成浏览器可理解的语法(commonjs).因此,将代码编译为给定的模块类型是没有意义的.
那么,这是否意味着您给出的模块类型会告诉编译器代码是用什么语法编写的呢?这意味着它必须从哪个代码编译成commonjs?但是我们有经常使用的模块类型commonjs
,但我们几乎从不使用纯commonjs语法编写代码.
答案是module specifies module manager
.我不明白那是什么意思.
我还考了Understanding “target” and “module” in tsconfig分和tsconfig module options - does 'System' refer to SystemJS?分.
这些似乎都不能正确回答我的问题.
tsconfig.json
{
"compilerOptions: {
"module": "esnext"
}
}