angularjs - Visual Studio 2015 在 ASP.NET Core 项目中不编译 TypeScript?
我正在使用 VS2015,并尝试在 ASP.NET Core 项目中使用 TypeScript 生成一个 Angular 应用,但无论我尝试什么,我都无法将我的 Angular 虚拟项目转译到 wwwroot 文件夹中,尽管 VS2015 已经将其识别为 TypeScript 虚拟项目。以下是我的项目结构:
这是我的 tsconfig.json 文件:
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"module": "system",
"experimentalDecorators": true,
"moduleResolution": "node",
"outDir": "../../wwwroot/"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
VS 不会自动编译这个,即使从命令行运行 npm run tsc:w main.ts 也会导致找不到文件的错误。我怎样才能让我的 ts 文件编译?
答案#1
@EchoLogic,尝试将你的 Angular 文件夹重命名为 scripts,应该可以。
答案#2
你的输出目录是相对于 tsconfig.json 的,所以你的路径应该像这样:../wwwroot/。这是我自己的 tsconfig.json 的一个例子:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outFile": "../wwwroot/app/app.js"
},
"compileOnSave": true,
"files": [
"../typings/main.d.ts",
"app.module.ts",
"app.config.ts",
"home.controller.ts",
"myTeam.controller.ts"
]}
我也更喜欢通过 gulp 构建 TypeScript。我已经发布了两篇关于如何做到这一点的文章:
在这里,您可以找到一个完整的逐步指南,说明如何配置您的 ASP.NET Core 应用以编译 TypeScript:ASP.NET Core:修改 Angular 应用以使用 TypeScript
以及如何使用 Gulp 工作流做到同样的事情:ASP.NET Core:使用 Gulp 构建 TypeScript
