对于React来说,去解析jsx的语法,主要依靠的是babel,module的中的@babel/preset-react
runtime:classic模式
const App=()=>{
return <div>
<h1>this is the title</h1>
<div>this is the context</div>
</div>
}
//解析后
const App = () => {
return React.createElement("div", null,
React.createElement("h1", null, "this is the title"),
React.createElement("div", null, "this is the context"));
};
runtime:automatic模式
const App=()=>{
return <div>
<h1>this is the title</h1>
<div>this is the context</div>
</div>
}
//解析后
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const App = () => {
return _jsxs("div", {
children: [_jsx("h1", {
children: "this is the title"
}), _jsx("div", {
children: "this is the context"
})]
});
};