Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript Build setting "Compile on Save" does not work in VS 2015, .js file is generated only during build

EDIT

Why is this issue extremely painful? So far while I debugged/tested my Web App I've just edited the .ts in VS IDE, saved, then reloaded the page and tested the changes. Now I have to build. However build is not enabled when debug session is running in the VS IDE. So now I have to do a complete roundtrip: edit .ts -> save -> stop debugging -> build -> launch debug. Again, this is extremely painful. END EDIT

I've unchecked / saved / checked the setting in TypeScript Build tab in my project setting.

enter image description here

The appropriate <PropertyGroup> was generated and saved to my .csproj file.

(note without changing any TypeScript Build setting, this <PropertyGroup> is not there (when using an existing project what was previously created with VS 2013), and the build defaults are not the same as the defaults on the IDE UI so you are misleaded.)

Anyway after this change / save activity my .csproj file is in sync with the IDE UI here it is:

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
  <TypeScriptRemoveComments>True</TypeScriptRemoveComments>
  <TypeScriptTarget>ES5</TypeScriptTarget>
  <TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
  <TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
  <TypeScriptModuleKind>None</TypeScriptModuleKind>
  <TypeScriptOutFile />
  <TypeScriptOutDir />
  <TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
  <TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
  <TypeScriptSourceMap>True</TypeScriptSourceMap>
  <TypeScriptMapRoot />
  <TypeScriptSourceRoot />
</PropertyGroup>

As it shows the Compile on Save is definitely enabled. Still the .js file only generated during build and not when the .ts file was saved.

Btw: Regarding that TypeScript compile is an msbuild task in VS 2015 implementation it is interesting how could this Compile on save setting even work...

More diagnostics: Interestingly in case if I delete the whole propertygroup then it actually compiles on save. (The UI remains the same, and the .map files are not generated on the save, only on build.)

like image 236
g.pickardou Avatar asked Jul 29 '15 08:07

g.pickardou


People also ask

Does TypeScript get compiled to JavaScript?

TypeScript is compiled to JavaScript. Therefore, TS can be used anywhere JS could be used: both the frontend and the backend. JavaScript is the most popular language to implement scripting for the frontend of apps and web pages.

Do TypeScript files need to be compiled?

Typescript is a superset of javascript but it is a strongly typed, object-oriented programming language. Typescript file does not run directly on the browser as javascript run, we have to compile the typescript file to the javascript then it will work as usual.

Where does TypeScript compile to JavaScript?

Directory dist/ is where the output of the compiler is stored. The TypeScript compiler compiles a TypeScript file such as ts/src/main. ts to a JavaScript file dist/src/main.

How do I save a file in TypeScript?

For example, for TypeScript 3.6. 0, you would use npm install --save-dev [email protected] . To preview the next version of TypeScript, run npm install --save-dev typescript@next .


2 Answers

did you look for the "Tools" menu < options... < Typescript < project and check the "compile on save" checkbox ?

like image 72
bqlou Avatar answered Sep 30 '22 19:09

bqlou


I got it working finally by adding "compileOnSave": true to my tsconfig.json.

So you tsconfig should look like :

{
    "compilerOptions": {
         ....
    },
    "compileOnSave": true
}
like image 22
Jaanus Avatar answered Sep 30 '22 20:09

Jaanus