讲个笑话先:某男是程序员,每天半夜三更才回家。某女抱怨:“你就不能提早点回家么?”某男:“好,一定。”于是下次某男一直写代码到天亮提着油条豆浆才回家。
好吧,不好笑。正文开始:
开发reactjs开发使用sublime时,想要代码高亮显示,需要安装babel-sublime插件,在Preferences中的Package Control菜单搜索Install Package安装插件。
1、babel-sublime可以从github中下载,地址:
https://github.com/babel/babel-sublime,安装在Packages文件夹
2、emmet 作为前端开发必备插件之一非常方便快捷,通过修改默认的 sublime就可以在 jsx 文件中快速通过 emmet 编写自定义组件
增强emmet兼容性
打开 preferences -> Key bindings - Users,把下面代码复制到[]内部。
[{
"keys": [
"super+e"
],
"args": {
"action": "expand_abbreviation"
},
"command": "run_emmet_action",
"context": [{
"key": "emmet_action_enabled.expand_abbreviation"
}]
},
{
"keys": ["tab"],
"command": "expand_abbreviation_by_tab",
"context": [{
"operand": "source.js",
"operator": "equal",
"match_all": true,
"key": "selector"
}, {
"key": "preceding_text",
"operator": "regex_contains",
"operand": "(\\b(a\\b|div|span|p\\b|button)(\\.\\w*|>\\w*)?([^}]*?}$)?)",
"match_all": true
}, {
"key": "selection_empty",
"operator": "equal",
"operand": true,
"match_all": true
}]
}]
//使用super+e触发 emmet;正则判断用 a,div,span,p,button标签默认tab 触发;
默认 class 修改为 className。
3、 sublimeLinter-jsx提示语法错误,JSX 代码审查, 帮助快速定位错误点.
PC上ctrl+shift+p(MacCmd+shift+p)打开面板输入sublimeLinter-jsx安装(依赖于 sublimeLinter)
安装 node.js
安装 jsxhint
4、jsformat 格式化js代码
打开preferences -> Package Settings -> JsFormat -> Setting - Users,输入以下代码:
{
"e4x": true,
// jsformat options
"format_on_save": true,
}