【发布时间】:2015-10-09 07:26:37
【问题描述】:
我在 index.html 中有这个 SystemJS 配置:
<body>
<script src="node_modules/systemjs/dist/system.js"></script>
<script>
System.config({
defaultJSExtensions: true,
transpiler: 'typescript',
map: {
typescript: 'node_modules/typescript/lib/typescript.js'
},
packages: {
"ts": {
"defaultExtension": "ts"
}
},
});
System.import('ts/main');
</script>
</body>
main.ts:
let a = [1, 2, 3];
let b = [1, 2, 3];
我得到:Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode。看起来文件没有被 SystemJS 转译。
当我在第一行添加导入语句时,它可以完美运行:
import * as ts from 'typescript'; // or any other package
let a = [1, 2, 3];
let b = [1, 2, 3];
看起来 SystemJS 通过“内容”识别打字稿文件 - 这是正确的吗?如果是,如何强制它转译每个 .ts 或 src/ 文件?
【问题讨论】:
标签: typescript systemjs