Search code examples
reactjswebpackecmascript-6babeljsjsx

How to configure Babel to transform only React JSX tags into JS?


I'm using React with Webpack and babel. I configured app by myself (not using create-react-app) but babel uses default configuration that translates es6 to es5. I only want to transform JSX to JS. Really, I only need support of the latest versions of macOS and iOS Safari and not any other browsers. Is it possible to configure webpack and/or babel like that?


Solution

  • As Felix Kling said, @babel/preset-react only transforms JSX elements to JS. Some legacy components (like function expressions and vars) are still in the bundle, but it's because of how Babel works.