Yoo*_*rek 4 typescript systemjs
我在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>
Run Code Online (Sandbox Code Playgroud)
main.ts:
let a = [1, 2, 3];
let b = [1, 2, 3];
Run Code Online (Sandbox Code Playgroud)
我明白了:Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode.它看起来像SystemJS没有编译文件.
当我在第一行添加import语句时,它完美地工作:
import * as ts from 'typescript'; // or any other package
let a = [1, 2, 3];
let b = [1, 2, 3];
Run Code Online (Sandbox Code Playgroud)
看起来SystemJS通过"内容"识别打字稿文件 - 这是正确的吗?如果是,如何强制它转换每个.ts或src /文件?
如您所料,systemjs猜测您在文件中使用的语法.您可以通过添加来帮助systemjs
// maybe you need to use " format:'register' " instead
System.config({
meta: {
'*.ts': {
format: 'es6'
}
}
});
Run Code Online (Sandbox Code Playgroud)
更多信息模块格式
| 归档时间: |
|
| 查看次数: |
2104 次 |
| 最近记录: |