简体   繁体   English

从Visual Studio中的TypeScript引用自动生成的JavaScript文件

[英]Referencing auto-generated JavaScript files from TypeScript in Visual Studio

I am developing a web application in Visual Studio 2012 and I have a solution with a few projects. 我正在Visual Studio 2012中开发Web应用程序,并且有一些项目的解决方案。 Also, I am using the TypesScript plugin (version 1.0RC) and I would like to keep all TypeScript development in a separate project while only referencing the auto-generated JavaScript files in projects that actually need to use them. 另外,我正在使用TypesScript插件(1.0RC版),并且我希望将所有TypeScript开发都保留在一个单独的项目中,同时仅在实际需要使用它们的项目中引用自动生成的JavaScript文件。 To do so, I have tried a couple of approaches but I'm not completely satisfied with none of them. 为此,我尝试了几种方法,但我都不完全满意。

Consider the directory tree of the two projects below: 考虑下面两个项目的目录树:

WebProject
|
– /img
– /includes
– /js
– index.html
– web.config

TypeScriptProject
|
– file1.ts
– file2.ts

I want to keep the updated version of all auto-generated JavaScript files from TypeScriptProject (in this case, file1.js and file2.js ) inside the js folder of WebProject . 我想将TypeScriptProject中所有自动生成的JavaScript文件(在本例中为file1.jsfile2.js )的更新版本保留在WebProjectjs文件夹中。 Here's what I've tried so far: 到目前为止,这是我尝试过的方法:

  1. Adding the JavaScript files as a regular file in WebProject : this doesn't work since a new copy of the file is created in the js folder. 将JavaScript文件作为常规文件添加到WebProject :这不起作用,因为在js文件夹中创建了文件的新副本。 This new copy won't reflect future changes made to the original TypeScript file. 这个新副本不会反映将来对原始TypeScript文件所做的更改。
  2. Adding the auto-generated JavaScript files as a link in WebProject : this seemed to work at first using some specific settings , but then I realized that it doesn't work in all environments for some reason I am not aware of yet. 将自动生成的JavaScript文件添加为WebProject的链接 :最初使用某些特定设置似乎可以正常工作,但是后来我意识到由于某种原因(我尚不知道),它不能在所有环境中都可以工作。

If anyone has a better solution in mind (or in use), it would be greatly appreciated. 如果有人在心中(或使用中)有更好的解决方案,将不胜感激。

You could use grunt-ts with the --outDir option : https://github.com/grunt-ts/grunt-ts#compiler-support 您可以使用带有--outDir选项的grunt-ts: https : //github.com/grunt-ts/grunt-ts#compiler-support

Here is a sample grunt file to get you started: https://github.com/grunt-ts/grunt-ts/blob/master/sample/Gruntfile.js 这是一个示例grunt文件,可帮助您入门: https//github.com/grunt-ts/grunt-ts/blob/master/sample/Gruntfile.js

Starting from VS 2013 Update 2 RC, now you can edit a TypeScript project settings in order to do exactly what was described in the question. 从VS 2013 Update 2 RC开始,现在您可以编辑TypeScript项目设置,以完全执行问题中所述的内容。

To do so, go to the project properties, then select the TypeScript Build tab. 为此,请转到项目属性,然后选择TypeScript Build选项卡。 In the Output area, check the option Redirect JavaScript output to directory and define which directory you want to copy your JavaScript files to. 在“ Output区域中,选中“ Redirect JavaScript output to directory ”选项Redirect JavaScript output to directory然后定义要将JavaScript文件复制Redirect JavaScript output to directory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeScript:自动生成的动态函数名称 - TypeScript: auto-generated dynamic function names 自动生成元素上的不显眼的 JavaScript 事件 - Unobtrusive JavaScript event on auto-generated elements Visual Studio 2013没有找到从typescript编译的javascript文件? - Visual Studio 2013 not finding javascript files compiled from typescript? 将 javascript 自动生成的文件附加到 POST 表单并在 $_FILES 中的 PHP 上处理它 - Append javascript auto-generated file to POST form and process it on PHP in $_FILES Webpack:无限循环和自动生成的文件 - Webpack: Infinite watch loop and auto-generated files 使用递增ID定位自动生成的字段(JavaScript) - Targeting Auto-Generated Fields with Incremented IDs (JavaScript) 使用Javascript / JQuery解析自动生成的.NET日期对象 - Parsing a Auto-Generated .NET Date Object with Javascript/JQuery 自动生成的Weebly侧边菜单,可能带有JavaScript或jQuery - Auto-Generated Side Menu for Weebly, perhaps with JavaScript or jQuery 使用自动生成的HTML表单更改JavaScript对象值 - Change JavaScript object values with auto-generated HTML form 如何使用 javascript 隐藏 jinja 自动生成的 forms? - How to hide jinja auto-generated forms using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM