systemjs - 在 TypeScript 的模块导入中默认使用 JS 扩展名
我正在尝试使用 system.js 将一个 TypeScript 模块导入到另一个文件中,但我必须在导入时指定 js 扩展名。
这是我的 app.ts 文件
import {PI, calculateCircumference} from "./math/circle.js";
console.log(PI);
console.log(calculateCircumference(10));
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Learning Typescript</title>
<script src="node_modules/systemjs/dist/system.js"></script>
</head>
<body>
<script>
System.import('/app.js');
</script>
</body>
</html>
当我尝试在 index.html 中使用以下代码时
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Learning Typescript</title>
<script src="node_modules/systemjs/dist/system.js"></script>
</head>
<body>
<script>
System.config({
baseURL : '/',
defaultJSExtensions : true
});
System.import('/app.js');
</script>
</body>
</html>
类型错误:System.config 不是一个函数
我哪里做错了?
这是我的 packages.json 文件
{
"name": "typescript",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "lite-server"
},
"author": "",
"license": "ISC",
"devDependencies": {
"lite-server": "^2.4.0"
},
"dependencies": {
"browser-sync": "^2.26.3",
"systemjs": "^2.0.2"
},
"keywords": [],
"description": ""
}