下面是我的tsconfig.json文件,其中我将目标设置为"es5",模块设置为"es6"
{
"compilerOptions": {
"target": "es5",
"module": "es6"
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是因为模块[import/export]是es6和NOT es5的一部分,转换后的javascript代码不应该有import/export语句.但即使目标是es5,生成的javascript代码也有导入/导出语句,怎么可能?
我正在阅读angular2推荐并找到了这个tsconfig.json.我想知道以下参数是什么意思?
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud) 试图对模块和目标有一些基本的了解.
我想知道典型的tsconfig.json中模块和目标编译选项之间的区别
{
"compilerOptions": {
"module": "es6",
"sourceMap": true,
"target": "es6"
}
}
如果我提供以下选项会发生什么:
module:commonjs,target:es6
module:es6,target:commonjs
module:commonjs,target:commonjs
在 tsconfig.json 文件中,可以将以下选项指定为 compilerOptions 'module' 属性的值:
System
Run Code Online (Sandbox Code Playgroud)
这样我们得到:
{
"compilerOptions": {
"module": "System",
...
Run Code Online (Sandbox Code Playgroud)
System 是否指 SystemJS(即,如果 SystemJS 被用作模块加载器,我在创建 AngularJS 或 Angular 应用程序时是否总是需要在我的 tsconfig.json 中使用“System”)?该文档似乎没有解释这一点:
https://www.typescriptlang.org/docs/handbook/compiler-options.html
在 TypeScript 的 Visual Studio 项目配置中,“TypeScript Build > Module system”下还有一个“System”选项,这显然与 tsconfig.json 中的“System”指代相同。