Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling React with Babel CLI

I am new to React and trying to learn. I am trying to compile a JSX simple file manually using babel CLI. I am using the following command.

npx babel src/App.js --out-file static/App.js

However it kind of gets stuck, and does not return.

Following are the contents of App.js

ReactDOM.render(
  <h1>Hello, world!</h1>,
  document.getElementById('example')
);
like image 799
Sarfraz Avatar asked Mar 13 '26 06:03

Sarfraz


1 Answers

You need the transform-react-jsx plugin

Working example :

npm install --save-dev @babel/cli @babel/core @babel/plugin-transform-react-jsx
npx babel App.js --out-file dist/App.js --plugins=@babel/plugin-transform-react-jsx

Which produces :

ReactDOM.render(React.createElement(
  'h1',
  null,
  'Hello, world!'
), document.getElementById('example'));
like image 74
Gabriel Bleu Avatar answered Mar 14 '26 20:03

Gabriel Bleu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!