在TypeScript中的模块导入中默认使用JS扩展

时间:2018-10-14 13:40:58

标签: typescript systemjs

我正在尝试使用system.js将打字稿模块导入另一个文件,但在导入时必须指定js扩展名。

这是我的app.ts文件

import {PI, calculateCircumference} from "./math/circle.js";
console.log(PI);
console.log(calculateCircumference(10));

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.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>

TypeError: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": ""
}

0 个答案:

没有答案