问题
I have created a TypeScript(.ts) file. Which upon save generates a minified JavScript file and a normal(readable) JavaScript file. All this works fine. But the comments I have added is TypeScript file is not visible in auto-generated JavaScript file. Since you cannot debug a TypeScript file (to add breakpoint, one need to use JavaScript file) and comments are not available in JavaScript file, I have to switch between .TS file and .JS file while debugging. Is there way to tell TypeScript, not to remove the comments user have added?
回答1:
If you have WebEssentials installed, you can set this in the WebEssentials Options:
If you do not have WebEssentials installed, stop what you are doing and go install it first from NuGet. This is a great extension that will add all kinds of helpful features for web development.
回答2:
Pass the --comments switch on the command-line to preserve comments.
回答3:
0.8.2.0
If you created a TypeScript project with version 0.8.2.0 of the TypeScript Visual Studio extension (the latest version), you'll find there is an option in the project file for this:
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<TypeScriptTarget>ES3</TypeScriptTarget>
<TypeScriptIncludeComments>false</TypeScriptIncludeComments>
<TypeScriptSourceMap>false</TypeScriptSourceMap>
</PropertyGroup>
By default it is false, but you can just switch it to true:
<TypeScriptIncludeComments>true</TypeScriptIncludeComments>
To edit this setting, you need to right-click on the project and select "Unload", then right-click on it again and hit "Edit". These settings are at the bottom of the file you will edit.
When you have changed the setting, right-click on the project again and hit "Re-load" and you'll be up and running again.
Previous Versions
In previous versions (if you created the project in a previous version, if you later updated to 0.8.2.0), you'll have to fiddle with the command, but the process is almost the same.
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\tsc" @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
Change it to this:
<Exec Command=""$(PROGRAMFILES)\Microsoft SDKs\TypeScript\tsc" --comments @(TypeScriptCompile ->'"%(fullpath)"', ' ')" />
Once again, to edit this setting, you need to right-click on the project and select "Unload", then right-click on it again and hit "Edit". These settings are at the bottom of the file you will edit.
When you have changed the setting, right-click on the project again and hit "Re-load" and you'll be up and running again.
来源:https://stackoverflow.com/questions/14639559/unable-to-see-comments-in-javascript-files-generated-by-typescript