搭建Sublime的TypeScript开发环境

作者: Floyda | 来源:发表于2018-03-09 11:26 被阅读117次

    搭建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
    <snippet>
        <content><![CDATA[for (let ${1:i} in ${2:Object}) {
        ${0:// code...}
    }]]></content>
        <tabTrigger>forin</tabTrigger>
        <scope>source.ts, source.tsx</scope>
        <description>for … in … loop</description>
    </snippet>
    
    

    相关文章

      网友评论

        本文标题:搭建Sublime的TypeScript开发环境

        本文链接:https://www.haomeiwen.com/subject/xxspfftx.html