This plugin will only remove the Fragment element if there's only one children. This can be
helpfull if you're rendering a SVG element which gets broken with the <undefined />
wrapper.
If there's multiple children this plugin will skip transformation.
yarn add babel-plugin-preact-fragment -D
# or
npm i babel-plugin-preact-fragment --save-dev
In your babel config:
plugins: [
'preact-fragment',
...
]
Be sure to include the code that's using React.Fragment, probably it's from node_modules.
{
test: /\.(jsx|js)?$/,
include: [
path.resolve('src'),
// Below is the module who's using React.Fragment
path.resolve('node_modules/@material-ui/icons'),
],
use: 'babel-loader'
},
Checkout tests/index.js (and the tests/fixtures dir) to see what this plugin is covering. If you find any cases where it's not working, you're welcome to file an issue.