天天看點

搭建typescript練習環境

-

1、node環境自備

2、全局安裝typescript

npm install -g typescript      

3、在VSCODE編輯器中建立TS檔案夾

  • 建立src根目錄
  • 建立app.ts
  • 編寫你的TS代碼

(1)通過指令行運作TS檔案

tsc ./src/app.ts --outFile ./dist/app.js
tsc ./src/* --outDir ./dist --watch      

(2)可以通過tsconfig.json配置檔案運作

  • tsc --init
  • 修改配置檔案
"outDir": "./dist",
"rootDir": "./src"      
  • 啟動
tsc --watch      

在app.ts中編輯的ts代碼會實時的編譯到dist/app.js中