[英]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.js
和file2.js
)的更新版本保留在WebProject
的js
文件夹中。 Here's what I've tried so far: 到目前为止,这是我尝试过的方法:
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文件所做的更改。 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.