2016-05-16 156 views
3

我有像這樣的結構的Visual Studio項目:的Visual Studio編譯沒有打字稿

Folder structure

tsconfig.json樣子:

{ 
    "compilerOptions": { 
    "noImplicitAny": false, 
    "noEmitOnError": true, 
    "removeComments": false, 
    "sourceMap": true, 
    "target": "es5", 
    "outDir": "../wwwroot/" 
    }, 
    "exclude": [ 
    "node_modules", 
    "wwwroot" 
    ] 
} 

然而,VS是不是編譯app.ts進入wwwroot文件夾。

我錯過了什麼?

+0

您是否在項目屬性 - >構建中選中了「編譯生成腳本」? –

+0

這是...我沒有建立!我認爲這是連續的而不是建立。感謝指針。 – BanksySan

+1

@BanksySan您可能正在尋找屬性> TypeScript Build –

回答

2

的Visual Studio內,項目>屬性>構建>確保 「編譯打字稿上構建」 被選中:

enter image description here

而且,在你tsconfig.json你應指定一個rootDir,以便TypeScript知道在哪裏尋找*.ts文件它sh烏爾德編譯:

{ 
    "compilerOptions": { 
    "noImplicitAny": false, 
    "noEmitOnError": true, 
    "removeComments": false, 
    "sourceMap": true, 
    "target": "es5", 
    "outDir": "../wwwroot/", 
    "rootDir": "../wwwroot/" 
    }, 
    "exclude": [ 
    "node_modules", 
    "wwwroot" 
    ] 
} 

細節被召喚出來的打字稿herehere上。

不要忘了實際構建它。這不是文件觀察器場景。

+0

Cheers David的「保存時編譯」。事實證明,我的謎題缺失的原因是我沒有意識到它是在構建時觸發的,我認爲它不斷地觀看這些文件。 – BanksySan

+0

Visual Studio實際使用tsconfig.json中的設置嗎? –

+0

@VernJensen絕對,如果他們被省略,那麼他們依靠默認值。 –

2

嘗試增加"compileOnSave": truetsconfig.json

{ 
    "compilerOptions": { 
     "noImplicitAny": false, 
     "noEmitOnError": true, 
     "removeComments": false, 
     "sourceMap": true, 
     "target": "es5", 
     "outDir": "../wwwroot/" 
    }, 
    "exclude": [ 
     "node_modules", 
     "wwwroot" 
    ], 
    "compileOnSave": true 
} 

應該編譯每次你現在節省時間。

+0

這是爲我做的。 –