如何在同一Visual Studio项目中混合使用Node.js和Typescript? [英] How to mix Node.js and Typescript in the same Visual Studio project?

查看:243
本文介绍了如何在同一Visual Studio项目中混合使用Node.js和Typescript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio有一个 Typescript 插件,用于使用Typescript语言开发应用程序.

Visual Studio has a Typescript addon for developing apps with the Typescript language.

还有用于VS的 Node.js 工具,通过它可以创建和调试Node.js应用程序.

And there is also the Node.js Tools for VS, with which one is able to create and debug Node.js applications.

我尝试创建一个Node.js项目,但是后来我无法向其中添加Typescript文件,并且如果我手动添加它们,它们将不会被编译为javascript(无法将其Build操作设置为TypeScriptCompile. )
而且,如果我创建一个简单的Typescript项目,则它不会使用Node启动我的应用程序,因为它基本上只是一个ASP.Net Web项目.

I tried creating a Node.js project, but then I couldn't add Typescript files to it, and if I added them by hand, they did not get compiled to javascript (couldn't set their Build action to TypeScriptCompile.)
And if I create a simple Typescript project, then it does not start my app with Node, because it is basically just an ASP.Net web project.

是否可以通过某种方式创建同时使用Typescript和Node.js集成的VS项目?

Is it possible to somehow create a VS project that uses Typescript and Node.js integration at the same time?

推荐答案

是的,可以,但是有点尴尬(我希望Node.js工具将来会更好地支持此功能).

Yes, it is possible, but in a somewhat awkward way (I hope Node.js Tools will support this better in the future).

您应该创建Node.js项目并添加一个新文件.选择新的文本文件,然后输入扩展名为.ts的文件.它将创建一个打字稿文件.

You should create Node.js project and add a new file. Choose new text file and enter its name with .ts extension. It will create a typescript file.

这时,您将拥有一个没有编译的javascript的打字稿文件.

At this point you will have a typescript files without compiled javascript.

要解决此问题,请转到VS工具"菜单,打开选项",然后转到文本编辑器">"TypeScript">项目",然后在保存时编译"下选中自动编译不包含在其中的TypeScript文件"项目,然后选择使用commonjs ...".

To fix this go to VS "Tools" menu, open "Options" and go to "Text editor" > "TypeScript" > "Project" and under "Compile on Save" check "Automatically compile TypeScript files which are not part of a project and choose "Use commonjs...".

之后,打开每个.ts文件并保存-tsc会将其编译为javascript.

After that open each .ts file and save it - tsc will compile it to javascript.

该解决方案的缺点是您必须记住手动保存每个编辑的.ts,但是我认为这没什么大不了的.

Downside of this solution is that you have to remember to save manually each .ts you edit, but I think its not a big deal.

以下是该帖子的链接,该帖子帮助我解决了相同的问题: http://blog.ctaggart.com/2013/11/nodejs-tools-with-typescript-console-app.html

Here's a link to the post that helped me with the same problem: http://blog.ctaggart.com/2013/11/nodejs-tools-with-typescript-console-app.html

更新

如果您使用Node.js工具的最新开发版本,则会看到已添加TypeScript支持.您可以创建TypeScript项目(其中包括调试.ts文件的功能)

If you grab the latest dev build of Node.js Tools you will see that TypeScript support is added. you can create TypeScript project (and this includes debugging .ts files feature)

https://nodejstools.codeplex.com/discussions/531222

这篇关于如何在同一Visual Studio项目中混合使用Node.js和Typescript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆