Babel in React (babel plugin: transform-react-jsx)

Ben Cheng
2 min readSep 23, 2019

--

@babel/plugin-transform-react-jsx

test.jsx

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

try to compile by babel

babel test.jsx

with @babel/plugin-transform-react-jsx plugin in .babelrc

Install @babel/plugin-transform-react-jsx

npm install @babel/core @babel/plugin-transform-react-jsx

Compile again

babel test.jsx --out-file test.js 
const profile = React.createElement("div", null, React.createElement("img", {
src: "avatar.png",
className: "profile"
}), React.createElement("h3", null, [user.firstName, user.lastName].join(' ')));

with source map

babel test.jsx --out-file test.js --source-maps

--

--

Ben Cheng

A developer in Hong Kong. Learning and rethinking as a developer. Welcome to contact me and make friend with me. Cooperation is welcome.