搭建Sublime的TypeScript开发环境

搭建Sublime的TypeScript开发环境

1. 安装TypeScript

安装Node.js, 然后npm install typescript -g

2. 安装Sublime的TypeScript插件

微软官方出品, 提供语法高亮, 代码补全, 定义跳转, 代码格式化等等功能

3. 修改TypeScript.sublime-build

Packages/User新建TypeScript.sublime-build, 或者在原文件(Packages/TypeScript/TypeScript.sublime-build)中修改.

{
    "selector": "source.ts, source.tsx",
    "shell":true,
    "windows":
        {
            "cmd": ["tsc", "$file", "&&", "node", "$file_base_name.js"]
        },
}

4. 自定义快捷键

  • 比如, 修改格式化代码
{ "keys": ["ctrl+alt+f"], "command": "typescript_format_document", "context":[{"match_all": true, "operator": "equal", "key": "selection_empty", "operand": true}, {"match_all": true, "operator": "equal", "key": "num_selections", "operand": 1}, {"operator": "equal", "key": "selector", "operand": "source.ts, source.tsx"}]},

5. 自定义Snippet

  • 比如, for-(in)-{}.sublime-snippet

    
    forin
    source.ts, source.tsx
    for … in … loop


你可能感兴趣的:(搭建Sublime的TypeScript开发环境)