跳至主要内容

@babel/plugin-transform-react-jsx-compat

示例

输入

JavaScript
var profile = (
<div>
<img src="avatar.png" class="profile" />
<h3>{[user.firstName, user.lastName].join(" ")}</h3>
</div>
);

输出

JavaScript
var profile = React.DOM.div(
null,
React.DOM.img({ src: "avatar.png", class: "profile" }),
React.DOM.h3(null, [user.firstName, user.lastName].join(" "))
);

安装

npm install --save-dev @babel/plugin-transform-react-jsx-compat

用法

babel.config.json
{
"plugins": ["@babel/plugin-transform-react-jsx-compat"]
}

通过 CLI

Shell
babel --plugins @babel/plugin-transform-react-jsx-compat script.js

通过 Node API

JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-react-jsx-compat"],
});