【问题标题】:ES6 ES2015 (Babel) Format / Beautfier for Sublime for .jsx .jsES6 ES2015 (Babel) 格式/美化器 for Sublime for .jsx .js
【发布时间】:2016-06-24 00:24:38
【问题描述】:

在使用 ES2015 进行 Reactjs 时,我希望能够在 Sublime 中格式化我的代码。

花了很长时间寻找这个问题的答案并找到了这个帖子 Is there a JSX formatter for sublime text?。但它似乎永远无法解决。 Babel 和 ESlint 为我做了一切,除了格式化代码。

【问题讨论】:

标签: javascript reactjs sublimetext3 babeljs


【解决方案1】:

您可以按照以下步骤安装 babel 语法。

    1.go to this url  https://packagecontrol.io/installation copy the code of sublime text 3 or sublime text 2 from the url

    2.open sublime text editor and go to menu options of View and select the "show console" 

    3.then paste the code from the above url and press enter.It will install the package manager.

    4.press ctrl+shift+p and type install in the input box. A list of options will come,then select the Install package option.It will install.

    5.After installing the above press again ctrl+shift+p and type the "babel" and select babel in the list.It will install the babel syntax

    6.to change the syntax of the page select the view menu and choose syntax/babel

【讨论】:

    【解决方案2】:

    你可以尝试为 sublime text 安装babel 主题,它支持所有 es6 和 jsx。你可以在这里找到它:https://github.com/babel/babel-sublime

    【讨论】:

      【解决方案3】:

      你试过sublime-jsfmt吗?添加esformatter-jsx 插件可能有助于格式化代码。 (免责声明:我做到了),对于一些需要修复的极端情况,它有一些错误,但对于最常见的情况,您可能会得到很好的结果。

      我想到的一件事是从头开始编写格式化代码,使用巴比伦来解析代码。目前它使用js-beautify。

      这里是online demo,如果你想试试的话

      【讨论】:

        猜你喜欢
        • 2015-12-18
        • 2016-05-03
        • 1970-01-01
        • 2016-07-18
        • 1970-01-01
        • 1970-01-01
        • 2019-02-20
        • 2016-06-02
        • 2022-12-09
        相关资源
        最近更新 更多