初始化 package.json npm init -y
初始化 tsconfig.json tsc --init
安装 parcel cnpm install parcel@next -D
tsconfig.json 找到配置
"outDir": "./dist",
"rootDir": "./src",
package.json 配置
"scripts": {
"test": "parcel ./src/index.html"
},
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script src="./page.ts"></script> </body> </html>
page.ts
const teacher: string = '222';
console.log(teacher);
执行命令 npm run test,控制台没报错,说明 parcel 会自动对 ts 文件进行编译