支持脚本类型="text/babel".在Visual Studio代码中 [英] Support for script type="text/babel" in Visual Studio Code

查看:516
本文介绍了支持脚本类型="text/babel".在Visual Studio代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Visual Studio Code中编辑以下示例HTML页面时(从Facebook的React教程中借用并稍作修改),如果我在脚本块中编写任何Javascript代码,则其语法为 not 突出显示.但是,如果我将脚本块类型更改为"text/javascript",则语法高亮显示有效.但是随后,任何React-y/JSX代码都无法正常工作,因为它可以通过Babel进行工作.

When I'm editing the below example HTML page in Visual Studio Code (borrowed from Facebook's React tutorial and slightly edited), if I write any Javascript code in the script block, it is not syntax highlighted. But if I change the script block type to "text/javascript" then the syntax highlighting works. But then any React-y/JSX code doesn't work as it is wired to work through Babel.

是否可以将脚本标签的类型"属性设置为文本/边框",同时在Visual Studio Code中突出显示正确的语法?

Is there any way to have the script tag "type" attribute set to "text/babel" and at the same time have proper syntax highlighting in Visual Studio Code?

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>React Tutorial</title>
    <script src="https://npmcdn.com/react@15.3.0/dist/react.js"></script>
    <script src="https://npmcdn.com/react-dom@15.3.0/dist/react-dom.js"></script>
    <script src="https://npmcdn.com/babel-core@5.8.38/browser.min.js"></script>
    <script src="https://npmcdn.com/jquery@3.1.0/dist/jquery.min.js"></script>
    <script src="https://npmcdn.com/remarkable@1.6.2/dist/remarkable.min.js"></script>
  </head>
  <body>
    <div id="content"></div>
    <script type="text/babel">
      ReactDOM.render(
        <div>Hello world!</div>,
        document.getElementById('content')
      );
    </script>
  </body>
</html>

推荐答案

我现在找到了解决方案.

I found a solution to this now.

打开:(VS code home dir)\resources\app\extensions\html\syntaxes\html.json,然后编辑脚本标签的正则表达式.这为我解决了这个问题.

Open up: (VS code home dir)\resources\app\extensions\html\syntaxes\html.json, and edit the regex for the script tag. That fixed the issue for me.

这篇关于支持脚本类型="text/babel".在Visual Studio代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆