文件目录:
root----index.html
|--main.ts
|--person.ts
|--package.json
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SystemJS</title>
<script src="node_modules/systemjs/dist/system.js"></script>
<script src="node_modules/typescript/lib/typescript.js"></script>
<script>
System.config({
transpiler: 'typescript'
});
System
.import('main.ts')
.then(null, console.error.bind(console));
</script>
</head>
<body>
</body>
</html>
main.ts
import {Person} from './person.ts';
let person = new Person("chenshixian");
console.log(person.name);
person.ts
import {Person} from './person.ts';
let person = new Person("chenshixian");
console.log(person.name);
package.json
{
"name": "testsystemjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "lite-server"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"lite-server": "^2.5.4",
"systemjs": "^0.19.47",
"typescript": "^3.8.3"
}
}
使用npm i 加载包
使用npm run dev启动web服务