TypeScript 使用Parcel打包TS代码


初始化 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 文件进行编译





免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM