的Visual Studio编译没有打字稿

的Visual Studio编译没有打字稿

问题描述:

我有像这样的结构的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 –

的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绝对,如果他们被省略,那么他们依靠默认值。 –

尝试增加"compileOnSave": truetsconfig.json

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

应该编译每次你现在节省时间。

+0

这是为我做的。 –