Reduce the size of final JSX code

Nikolay Kost
Sep 7, 2018 · 1 min read

What do we need?

.babelrc

presets: [
['@babel/react', {pragma: 'h'}]
]

webpack.config.js

plugins: [
new webpack.ProvidePlugin({
h: ['react', 'createElement']
})
]

And result is

Before optimization
After optimization

What does this hack do?

It’s simply transforms React.createElement to h function calls.

Before optimization
After optimization

Nikolay Kost

Written by

React, Redux, Node.js, PHP, Yii2

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade