Typescript compile on save not working in cordova .jsproject - 2015

有些话、适合烂在心里 提交于 2019-12-11 03:13:23

问题


I have Typescript 1.5 beta tools for Visual Studio 2015 installed, and I create a new Cordova Typescript project. The project template includes some .ts files but I cannot get these to compile on save.

Strangely if I create a new project using the Html 5 with Typescript template, the app.ts file does compile on save. It's only in this .jsproj cordova project that it ignores TypeScript compilation. Why?

I see that they use different targets (for the Html 5 project uses Microsoft.Typescript.targets where as in the cordova project is uses Microsoft.TypeScript.MDA.targets:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\ApacheCordovaTools\vs-mda-targets\Microsoft.TypeScript.MDA.targets" />

For both cases I verified the files exist in their respective locations. I even tried to use the non MDA target instead; no luck. I also included an empty tsconfig.json file at the root of the project, still no luck.

How can I get Typescript file to compile on save like they do in other project types?

I also have ENABLED Tools > Options > Text Editor> Typescript > Compile files that are not part of the project as well as installed Web Essentials 2015... Nothing works!


回答1:


I did not have a try but see if you can get it work by change the value of <TypeScriptIncludeComments>false</TypeScriptIncludeComments> from false to true in prject file for both Debug and Release build.




回答2:


Same problem here, I created the project added typedefinition files and no luck in getting js files.

EDIT

Finally I found what's going on you can check the file appBundle.js all type scripts files are compiled and saved in one file I think it's something related to gulp or Grunt.




回答3:


same problem here, just found a working solution for me! in your jsproject file add/edit the following lines:

  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptCompileOnSaveEnabled>true</TypeScriptCompileOnSaveEnabled>
    <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptCompileOnSaveEnabled>true</TypeScriptCompileOnSaveEnabled>
    <TypeScriptRemoveComments>true</TypeScriptRemoveComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
  </PropertyGroup>

note the "TypeScriptCompileOnSaveEnabled" property with "true" value.




回答4:


You could simple to setup use: Tools > Options > Text Editor > TypeScript > Project > General, and check "Compile on Save" then OK. And here you go.

Another way I'm used task runner called "grunt-ts" to do so, I'm prefer to use task runner to help me to compiled the .ts file, it also provide detail feature include watch to do so.



来源:https://stackoverflow.com/questions/30430126/typescript-compile-on-save-not-working-in-cordova-jsproject-2015

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