.netcore TypeScript Setup

設定檔tsconfig.json

預設在Vs2015 加入.ts檔案,就會自動在每次儲存時complier,輸出js檔,若要進階設定,.netCore的專案需在根目錄加入組態檔tsconfig.json。參考如下:
tsconfig.json
{
  "compilerOptions": {
    "noImplicitAny": true,
    "noEmitOnError": true,
    "sourceMap": true,
    "target": "es5",
    "module": "commonjs"
  },
  "exclude": [
    "node_modules",
    "wwwroot/lib",
    "bin",
    "obj"
  ],
  "compileOnSave": true
}
  1. 上方的exclude,會排除目錄內的.ts。
  2. 若不使用exclude,只想針對特定檔案的話,可以使用files參數,此參數要明確指定檔名,例:
files:[‘./wwwroot/js/app.ts’]

定義檔(.d.ts)

由於.netcore的目錄結構不同以往,不能使用nuget來下載,需透過npm的typings下載
安裝typings 套件
npm  install typings -g 
安裝定義檔套件(本例使用jquery)
typings install dt~jquery --global --save

參考來源

https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/tutorials/ASP.NET%20Core.html
https://github.com/typings/typings
https://www.typescriptlang.org/docs/handbook/asp-net-core.html

這個網誌中的熱門文章

IIS 設定只允許特定IP進入