How to configure Visual Studio to combine all TypeScript files into one JavaScript file?

时光怂恿深爱的人放手 提交于 2019-12-01 02:09:28

问题


Using tsc command it's as easy as running:

tsc --out all.js js/*.ts

How can I configure Visual Studio to do that when I build my project?


回答1:


I've found a potentially easier solution by just modifying the build properties of the project (.csproj / .vbproj) you are building:

I'm unsure which version of Typescript that this feature was introduced in. But it seems a much simpler method than the svallory's solution

Source: http://rostacik.net/2013/12/18/how-to-setup-post-build-event-in-visual-studio-to-combine-multiple-typescript-files-to-one-javascript-file/

EDIT: Since Visual Studio 2015, it's now very easy to integrate Grunt/Gulp tasks and have them run in your builds. I've personally be really enjoying using Gulp for more granular control over what files I build and/or minify, and I highly recommend it. Using this guide as a starting point should help.




回答2:


Just got it. Add this line:

<Exec Command="tsc --out all.js @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />

to the BeforeBuild target of your .csproj or .vbproj file, like this:

<Target Name="BeforeBuild">
    <Message Text="Compiling TypeScript files" />
    <Message Text="Executing tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
    <Exec Command="tsc$(TypeScriptSourceMap) @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
    <Exec Command="tsc --out all.js @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>



回答3:


It seems that the proposed solution is for typescript 0.8.1.1 and not 0.8.2



来源:https://stackoverflow.com/questions/14302686/how-to-configure-visual-studio-to-combine-all-typescript-files-into-one-javascri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!