如何在没有require()或requireJS的情况下在Visual Studio 2015中运行TypeScript [英] How to run TypeScript in Visual Studio 2015 without require() or requireJS

查看:250
本文介绍了如何在没有require()或requireJS的情况下在Visual Studio 2015中运行TypeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个新的Web项目,我想在其中开始工作/学习TypeScript。一个空的c#.net Web项目中的该项目未使用MVC,Angular等。它只是普通的html和Ts。一切运行顺利,直到我开始设置模块(类,接口等)。一旦开始导出和导入模块,我就开始在开发工具中收到错误 Uncaught ReferenceError:require尚未定义。查看实际的js文件,我可以看到它将文件的主体包装在require()中。
这个项目很小,如果可能,我不想设置requireJs。有没有办法禁用VS中的Ts编译器​​以不插入require()函数?没有使用node.js,并且在项目属性中,我已将Modules系统从CommonJS切换到Es2015。

I've setup a new web project where I wanted to begin working/learning TypeScript. This project while an empty c#.net web project is not using MVC, angular, etc. It is just plain vanilla html and Ts. Everything was running smooth until I started setting up modules (classes, interfaces etc.) Once I started exporting and importing the modules I began receiving in the dev tools the error Uncaught ReferenceError: require is not defined. Looking at the actual js file I can see it is wrapping the body of the file in a require(). This project is small and I don't want to setup requireJs if possible. Is there are way to disable the Ts compiler in VS to not insert the require() function? node.js is not being used and within the project properties I have switched the Modules system from CommonJS to Es2015.

或者我在这里完全丢失了一些东西,应该将它们捆绑在一起文件?

Or am I totally missing something here and should be bundling these files?

我将进出口声明为:

interface.ts

interface.ts

import  {Category }  from './enums';

interface ICar {
    id: number;
    make: string;
    model: string;
    vin?: string;
    mileage?: number;
    category: Category;
}

export { ICar }

enum.ts

enum Category { Antique, Sportscar, Truck, SUV, Sedan };

export { Category };

并且在我的主文件应用程序顶部。我引用了模块

and at the top of my main file app.ts I reference the modules

import { Category } from './enums'; 
import { ICar } from './interfaces'; 

一旦在我的主文件app中编译了js输出,js就会在标头中包含

Once compiled the js output in my main file app.js contains this at the header

"use strict";
var enums_1 = require("./enums");

感谢任何建议

推荐答案

您可以在Visual Studio项目中设置打字稿,如下所示:

You can set up typescript in visual studio project like this:

然后,如果您从不使用导出或导入,则可以工作。对于正确的文件链接(将所有内容绑定在一起时),请不要忘记将引用添加到ts文件的顶部:

Then if you never use export or import, you will be able to work. For proper files chaining (when bundlig all together) don't forget to add your references at the top of your ts files:

/// <reference path="path/mytool.class.ts" />

这篇关于如何在没有require()或requireJS的情况下在Visual Studio 2015中运行TypeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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