Visual Studio not compiling TypeScript

2019-06-23 07:43发布

I have a Visual Studio project with a structure like so:

Folder structure

My tsconfig.json looks like:

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

However, VS isn't compiling the app.ts into the wwwroot folder.

What am I missing?

2条回答
叼着烟拽天下
2楼-- · 2019-06-23 08:34

From within Visual Studio, Project > Properties > Build > ensure that the "Compile TypeScript on build" is checked:

enter image description here

Also, in your tsconfig.json you should specify a rootDir so that TypeScript knows where to look for *.ts files it should compile:

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

The details are called out on the TypeScript page here and here.

Don't forget to actually build it. It isn't a file watcher scenario.

查看更多
手持菜刀,她持情操
3楼-- · 2019-06-23 08:41

Try adding "compileOnSave": true to your tsconfig.json:

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

It should compile every time you save now.

查看更多
登录 后发表回答