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