搭建Sublime的TypeScript开发环境
2018-03-09 本文已影响117人
Floyda
搭建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>