Typescript is a superset of JavaScript built-in, adding optional static types and object-oriented programming to help us develop large web applications. Sublime Text is a code editor, with a beautiful user interface and strong plug-in support, through the Sublime to write Typesript can let us go to the duck, Sublime support the build function, can compile some common language, However, the compilation of Typesript to JavaScript cannot be completed. But it doesn't matter, we can use the manual settings to make these two big artifacts tightly linked together. First, we're going to use NPM to install the typescript package globally. We have been able to compile the typescript file with the. TS by using the TSC command at the command line. For example: But this is a lot of inconvenience, if we can fully compile in the editor is not more simple and friendly. So the next step is to add typescript compile functionality to sublime. Open Sublime Text--Tools--build system--new build system Next, paste the following code into the newly opened window
1 {2 "cmd": ["TSC","$file"],3 "File_regex":"(. *\\.ts?) \\s\\ ([0-9]+) \ \ ([0-9]+) \ \) \\:\\s (...) $",4 "selector":"source.ts",5 6 "Windows": {7 "cmd": ["Tsc.cmd","--target","ES5","$file"]8 }9}
Select Save and add to the default path, the file name is Typescript.sublime-build
To do this we have achieved the goal of compiling the typescript file in sublime text, and then we'll test
After writing a typescript file, press CTRL + B at the same time, if the [finished in 1.4s] Prompt field is displayed below, the generated JS file will be visible in the current directory if the file is compiled successfully.
This is the end of the tutorial, I hope you have fun ~
Compiling the typescript file using the build command in SUBLIME2/3