typescriptsublimetext3auto-compile

Typescript compile on save in sublime 3


Is there any way to force Sublime text 3 to compile Typescript code on save? It's a bit annoying switching back and forth between terminal and Sublime. Thanks!


Solution

  • I don't know how to do it on save but you can do it by clicking ctrl+b. In order to make it work do this:

    1. go to Tools->Build System->New Build System
    2. copy and paste the following:

      {
          "cmd": ["tsc","$file"],
          "file_regex": "(.*\\.ts?)\\s\\(([0-9]+)\\,([0-9]+)\\)\\:\\s(...*?)$",
          "selector": "source.ts",
      
          "windows": {
              "cmd": ["tsc.cmd", "$file"]
          }
      }
      
    3. save it as "myTypeScript.sublime-build"

    4. Tools->Build System and choose the build system that you just created "myTypeScript.sublime-build"

    5. every time you want to compile just click on ctrl+b

    You can see seome explanation about it and more here