Visual Studio Typescript转换为JavaScript [英] Visual Studio Typescript to JavaScript

查看:267
本文介绍了Visual Studio Typescript转换为JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的visual studio 2015项目中,我创建了一个打字稿文件file1.ts.我的项目根文件夹中也有一个tsconfig.json文件.我通过npm在全球范围内安装了tsc.我还从以下位置为Visual Studio安装了打字稿: https://www.microsoft.com/en-us/download/details.aspx?id=48593

In my visual studio 2015 project I created a typescript file file1.ts. I have also a tsconfig.json file in my project root folder. I installed tsc globally via npm. I also installed typescript for visual studio from here: https://www.microsoft.com/en-us/download/details.aspx?id=48593

但是当我编译项目时,我没有从.ts文件中获取任何.js文件.但是我有一个Typescript虚拟项目.在stackoverflow上阅读了很多文章之后,我做了很多尝试来查找问题.有些人在项目属性"窗口中发布了屏幕截图,您可以在其中看到"Typescript选项":

But when I'm compiling my project, I don't get any .js file from my .ts file. But I got a Typescript Virtual Project. After reading a lot of posts here in stackoverflow, I tried a lot to find the problem. Some people posted screenshots where you can see, that they have "Typescript Options" in Project Properties window like here:

打字稿虚拟项目看起来像:

The typescript virtual project looks like:

在.ts文件中,我使用一些示例代码:

In the .ts file I use some example code:

class Startup {
    public static main(): number {
        console.log('Hello World');
        return 0;
    }
}

tsconfig.json代码为:

And the tsconfig.json code is:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true
  }
}

我该怎么做才能让编译器从项目的.ts文件中创建.js文件?

What do I have to do to let the compiler create .js files from my .ts files of my project?

我知道在Visual Studio 2015中,如果您使用asp.net 5项目模板,它是开箱即用的.但是我有一个现有项目,但那里没有工作.因此,必须有一个选项可以为现有项目获得此功能!?

I know in Visual Studio 2015 it is working out of the box if you use asp.net 5 project templates. But I have an existing project and it isn't working there. So there must be an option to get this functionality for existing projects!?

推荐答案

只要您使用的是至少RTM版本的VS 2015,您就不需要使用IF如果您正在使用Visual Studio 2015.我假设您是因为那是您发布的扩展页面:)

You don't need any of that IF you are using Visual Studio 2015 its out of the box as long as you are using at least RTM version of VS 2015. I'll assume you are since that was the extension page you posted :)

例如-只需创建一个新的ASP.NET 5项目,放入.ts文件,然后添加一些代码即可.请注意,我的打字稿文件在此处显示了.ts及其经过处理的.js文件.如果使用2015,则不需要npm,附加安装等,它们都是开箱即用的.

For example - just create a new ASP.NET 5 project, drop in a .ts file, add some code. Notice my typescript file here shows the .ts and its processed .js file underneath it. The npm, add-in install, etc are all unncessary if using 2015, it is handled out of the box.

请注意,对于MVC 5项目,它的显示效果不是很好.单击显示所有文件"图标,该图标位于下面右侧图标的第三个图标中,然后在添加.ts文件后将看到.js文件.我的项目视图一刷新,便立即出现(确保您单击了项目,然后您会在解决方案资源管理器中看到刷新图标)

Note that for MVC 5 projects, it doesn't show up quite as nice. Click the "Show all files" icon which is the third from the right icon below and then you'll see your .js file after you've added a .ts file. Mine appeared as soon as I refreshed the project view (ensure you are clicking on your project and then you'll see the refresh icon show up in solution explorer)

这篇关于Visual Studio Typescript转换为JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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