How Gutenberg exposes @wordpress packages

Last Updated on December 25, 2020 by Neil Murray

gutenberg/webpack.config.js

ln 105-113

[
	...entryPointNames,
	...packageNames,
	...coreGlobals,
].forEach( ( name ) => {
	externals[ `@wordpress/${ name }` ] = {
		this: [ 'wp', camelCaseDash( name ) ],
	};
} );

This reconfigures imports to use the global version, so that e.g. import from '@wordpress/blocks' points to wp.blocks

The same configuration does expose on the global as well using:

ln 130-135

	output: {
		filename: '[basename]/build/index.js',
		path: __dirname,
		library: [ 'wp', '[name]' ],
		libraryTarget: 'this',
	},