Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@automattic/babel-plugin-transform-wpcalypso-async

Package Overview
Dependencies
Maintainers
33
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@automattic/babel-plugin-transform-wpcalypso-async

A Babel plugin to facilitate optional code-splitting by applying transformations to a `asyncRequire` global function or the `` React component

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
33
Created
Source

Calypso Async Babel Transform Plugin

babel-plugin-transform-wpcalypso-async is a Babel plugin to facilitate optional code-splitting by applying transformations to a asyncRequire global function or the <AsyncLoad /> React component.

Usage

Include in your Babel configuration as a plugin.

Example Babel config file:

{
	"plugins": [
		[ "@automattic/transform-wpcalypso-async", { "async": true } ]
	]
}

See Babel options documentation for more information.

Transformations

asyncRequire will transform to one of:

  • dynamic import() if async plugin option is true
  • static require if async plugin option is false or unset
  • nothing (will be removed and no module will be imported) if the ignore plugin option is true

asyncRequire expects one required argument, with an optional callback:

asyncRequire( 'calypso/components/search', ( Search ) => {
	console.log( Search );
} );

<AsyncLoad /> will transform its require string prop to a function invoking asyncRequire when called.

// Before:

<AsyncLoad require="calypso/components/search" />;
// After:

<AsyncLoad
	require={ function ( callback ) {
		asyncRequire( 'calypso/components/search', callback );
	} }
/>;

Options

  • async - controls whether transformations applied by the plugin should use a dynamic ESM import statement that enables webpack code-splitting or the synchronous CommonJS require function. This defaults to false.
  • ignore - if set to true, the asyncRequire call will be completely removed, and AsyncLoad will show the placeholder forever and won't do any import. Useful for server side rendering where the render is one-pass and doesn't wait for any imports to finish.

FAQs

Package last updated on 17 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc