我一直在试用最新版本的 Angular2 (2.0.0-alpha.44) 以及 Visual Studio 2015。以下是我使用的与此问题相关的所有版本:
- Visual Studio 2015
- ASP.NET 5
- typescript 1.6
- Resharper 10
- Angular 2.0.0-alpha.44
这是我的解决方案:
我所有的 typescript 都在/Ts 目录中,其中还有一个 tsconfig.json 文件。这使得 Visual Studio 显示一个“ typescript 虚拟项目”
一旦我将 import {Component, bootstrap} from "angular2/angular2";
行放入我的 main.ts 中,它就会找到 angular2 库文件我的 node_modules
目录并显示这些目录(虽然不确定扁平目录结构是什么)
此时,typescript 编译器将编译该单个文件 (main.ts)。但是,它不再编译该文件夹中的任何其他 .ts 文件(在引入 angular2 之前),并且它不会将输出放在指定的 outFile
位置我的 tsconfig.json
Resharper 表示在查找 Component
和 bootstrap
引用时出现问题,但工具提示似乎也理解它们的签名是什么。不确定两者怎么可能是真的。
如果我从等式中删除 angular2,typescript 会愉快地遵循我的 tsconfig.json 中的所有设置,将所有 .ts 文件编译成 app.js 并将其放入 ../wwwroot/js/app.js
有没有人成功地让 VS2015、typescript 和 angular2 很好地协同工作?
最佳答案
In TypeScript, just as in ECMAScript 2015, any file containing a top-level import or export is considered a module.
和
Just as there is a one-to-one correspondence between JS files and modules, TypeScript has a one-to-one correspondence between module source files and their emitted JS files. One effect of this is that it's not possible to use the --outFile compiler switch to concatenate multiple module source files into a single JavaScript file.
我相信这就是当您“从等式中删除 angular2”时得到输出的原因。模块和 outFile
不兼容。请改用 outDir
。
此外,我曾尝试将 tsconfig 文件放在子文件夹中,但 Visual Studio 不支持它,因此我将其移回了项目根目录。
关于typescript - 带有 tsconfig.json 的 Visual Studio 2015、Typescript 和 angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33532864/