在typescript中的模块导入中默认使用JS扩展
我试图使用system.js将typescript模块导入到另一个文件中,但我必须在导入时指定js扩展名 这是我的app.ts文件在typescript中的模块导入中默认使用JS扩展,typescript,systemjs,Typescript,Systemjs,我试图使用system.js将typescript模块导入到另一个文件中,但我必须在导入时指定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
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>
我认为只有SystemJS版本0.x才支持
System.config
,而您使用的是SystemJS 2.x。所以,如果js扩展是默认的,那么应该怎么做呢。新的做法是什么?
<!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>
{
"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": ""
}