This is a replica of react-loadable's babel plugin.
- Removed flow based personal preference.
- Added an option
source
to specify the name of the imported library, defaults to "react-loadable". - Split into a seprate repository as this is a development dependency, while the main library is not.
if you are using react-loadable/babel
this is not needed because sadly the plugin is baked inside the library.
yarn add --dev react-make-async-babel-plugin
Included in the react-loadable
package is a Babel plugin that can add
serverSideRequirePath
and webpackRequireWeakId
for you.
Input:
import Loadable from 'react-loadable';
Loadable({
loader: () => import('./MyComponent'),
LoadingComponent: () => null,
});
Output:
import _path from 'path';
import Loadable from 'react-loadable';
Loadable({
loader: () => import('./MyComponent'),
LoadingComponent: () => null,
serverSideRequirePath: _path.join(__dirname, './MyComponent'),
webpackRequireWeakId: () => require.resolveWeak('./MyComponent'),
});
If you have react-loadable
installed already, all you need to do is add this
plugin to your Babel config:
{
plugins: [
["react-make-async-babel-plugin", {
server: true,
webpack: true
}]
]
}
Options:
server
(default:true
) - Whentrue
addsserverSideRequirePath
config.webpack
(default:false
) - Whentrue
addswebpackRequireWeakId
config.source
(default:react-loadable
) - match against the library name to add the properties to its configs object.