怎么让sublime支持react语法
sublime支持react语法可以通过安装插件来实现,以下要安装的插件,要是在install package中没有找到,说明已经安装过了,可以在菜单Preferences -> Package Settings中查看已经安装过的插件
1.安装Babel插件语法转义
安装command+shift+p -> install package -> babel
配置
该插件不需要额外配置,在打开.js或.jsx后缀的文件,直接选择Babel为对应的语法就可以了。可以支持ES6和JSX语法
2.Emmet:可以自动扩展react的className
可自动补全代码
安装command+shift+p -> install package -> emmet
配置
打开菜单Preferences -> Package Settings -> Emmet -> Key Bindings - User
粘贴下面的代码[{
"keys": ["tab"],
"command": "expand_abbreviation_by_tab",
// put comma-separated syntax selectors for which
// you want to expandEmmet abbreviations into "operand" key
// instead of SCOPE_SELECTOR.
// Examples: source.js, text.html - source
"context": [{
"operand": "source.js",
"operator": "equal",
"match_all": true,
"key": "selector"
},
// run only if there's no selected text
{
"match_all": true,
"key": "selection_empty"
},
// don't work if there are active tabstops
{
"operator": "equal",
"operand": false,
"match_all": true,
"key": "has_next_field"
},
// don't work if completion popup is visible and you
// want to insert completion with Tab. If you want to
// expand Emmet with Tab even if popup is visible --
// remove this section
{
"operand": false,
"operator": "equal",
"match_all": true,
"key": "auto_complete_visible"
}, {
"match_all": true,
"key": "is_abbreviation"
}
]
}]
3.jsformat
jsformat是sublime上js格式化比较好用的插件之一,通过修改它的e4x属性可以使它支持jsx。
安装command+shift+p -> install package -> jsformat
配置
打开菜单Preferences -> Package Settings -> JsFormat -> Settings - User,将下面代码贴进去保存。{
"e4x": true,
// jsformat options
"format_on_save": true,
}
4.sublime中装入小程序的自动补全和高亮的插件(Sublime wxapp)
点击菜单栏 Preferences(首选项) ==> Package Control
在弹出的 Package Control 搜索框内输入 Install Package ,回车。
然后在弹出的 Install Package 搜索框内输入 Sublime wxapp 回车,进行自动安装
本文来自React答疑栏目,欢迎学习!