简体   繁体   English

VS Code如何将HTML合并为.JS文件?

[英]VS Code how to combine HTML into .JS file?

I try to create a React project in VS Code. 我尝试在VS Code中创建一个React项目。 When I try to save index.js with the HTML tags as below, VS Code breaks my tags and pushes spaces between words and brackets. 当我尝试使用以下HTML标记保存index.js时,VS Code破坏了我的标记并在单词和方括号之间添加了空格。 Can't find how I can fix it… 找不到解决方法...

// this is before I safe the project
ReactDOM.render( <div> Hello World! </div>, document.getElementById('root'))

// this is after I safe the project
ReactDOM.render( < div > Hello World! < /div>, document.getElementById('root'))

Either: 或者:

  1. Change all .js file extensions to .jsx . 将所有.js文件扩展名更改为.jsx
  2. Add file association in user/workspace settings: 在用户/工作区设置中添加文件关联:
"files.associations": {
    "*.js": "javascriptreact"
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM