Async transformation utilities for the WordPress.com Calypso project
npm install babel-plugin-transform-wpcalypso-asyncCalypso Async Babel Transform Plugin
====================================
babel-plugin-transform-wpcalypso-async is a Babel plugin intended for use with the WordPress.com Calypso project, facilitating optional code-splitting by applying transformations to a asyncRequire global function or the React component.
Include in your Babel configuration as a plugin.
Example .babelrc file:
``json`
{
"plugins": [
[ "transform-wpcalypso-async", { "async": true } ]
]
}
See Babel options documentation for more information.
asyncRequire will transform to one of:require.ensure
- if async plugin option is truerequire
- if async plugin option is false or unset
asyncRequire expects one required argument, with an optional callback:
`js`
asyncRequire( 'components/accordion', ( Accordion ) => {
console.log( Accordion );
} );
will transform its require string prop to a function invoking asyncRequire when called.
`js
// Before:
// After:
} } />
`
The plugin accepts a single option, async, which controls whether transformations applied by the plugin should should Webpack code-splitting require.ensure or the synchronous CommonJS require function. This defaults to false`.
Calypso and related projects are licensed under GNU General Public License v2 (or later).