javascript - How to reference a TypeScript file from a web page - Stack Overflow

PreambleI can get this to work but I'm not sure I'm using the technology as Microsoft intende

Preamble

I can get this to work but I'm not sure I'm using the technology as Microsoft intended.

Context

A web page can refer to a JS file containing JavaScript by means of a reference tag like this:

<script src="Scripts/jquery.js"></script>

In the above example, the JS file is part of a Visual Studio ASPX.NET project. It was both placed in the project Scripts folder and added to the project by Nuget.

Having added a Typescript file to an existing ASP.NET project, I would like to use the generated JS from an ASPX web page.

Instructing Solution Explorer to show all files reveals that the expected JS file has indeed been generated on the expected path.

Am I using this correctly? What is the remended method?

There are a couple of ways one might go about things.

  • Refer directly to the generated JS file

I was concerned that files not part of a project would be excluded from a web server deployment, but have since determined that they are deployed.

  • Add some kind of reference to the Typescript file

It would be great if there were some syntax for a reference to the TS file that will be transformed into a script tag referring to the generated JS file. Alas, if this exists it's not very well publicised.

Preamble

I can get this to work but I'm not sure I'm using the technology as Microsoft intended.

Context

A web page can refer to a JS file containing JavaScript by means of a reference tag like this:

<script src="Scripts/jquery.js"></script>

In the above example, the JS file is part of a Visual Studio ASPX.NET project. It was both placed in the project Scripts folder and added to the project by Nuget.

Having added a Typescript file to an existing ASP.NET project, I would like to use the generated JS from an ASPX web page.

Instructing Solution Explorer to show all files reveals that the expected JS file has indeed been generated on the expected path.

Am I using this correctly? What is the remended method?

There are a couple of ways one might go about things.

  • Refer directly to the generated JS file

I was concerned that files not part of a project would be excluded from a web server deployment, but have since determined that they are deployed.

  • Add some kind of reference to the Typescript file

It would be great if there were some syntax for a reference to the TS file that will be transformed into a script tag referring to the generated JS file. Alas, if this exists it's not very well publicised.

Share Improve this question edited Jan 28, 2016 at 2:59 Peter Wone asked Jan 19, 2016 at 22:47 Peter WonePeter Wone 18.9k14 gold badges95 silver badges148 bronze badges 2
  • you should observe your page over the browser and inspect if the rendering process (server-side) has generated the reference... if it does - you don't need to do anything.. if you are missing that reference (as an HTML document) YOU SHOULD ADD IT MANUALLY – ymz Commented Jan 19, 2016 at 22:56
  • There are a number of ways to do this, from using an HTTP handler to serve the piled JS when a request for the TS is made, to just typing in the reference using a standard <script src=" element into your HTML file. You might want to look into the Bundling and Minification feature of ASP.NET also. – Heretic Monkey Commented Jan 19, 2016 at 23:08
Add a ment  | 

1 Answer 1

Reset to default 4

In VS2015, dragging the TS file onto an HTML or ASPX page in the editor will insert a link tag referring to the corresponding JS file.

DO NOT use server URL rewriting to remap references to the TS file to the JS file. This interferes with VS and browser debug support via source map files.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745207207a4616648.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信