Gutenberg comes with a set of core libraries which are necessary for any kind of custom block development. Namely those libraries are: @wordpress/components: Generic, reusable UI WordPress components
@wordpress/i18n: Internationalization utilities
@wordpress/element: Abstraction on top of React
@wordpress/date: Date formatting and manipulation utilities
@wordpress/blocks: Module providing utilities for registering and building blocks
@wordpress/data: Abstraction on top of Redux
@wordpress/editor: Module representing the WordPress Editor’s page
@wordpress/utils: Various generic utilities
To use them you need to include them as external script requirements to your final build by registering and enqueueing them, similarly to how you’d include any kind of script or style within WordPress.
function my_plugin_enqueue_editor_assets() {
wp_enqueue_script( ‘myplugin’, untrailingslashit( MY_PLUGIN_DIR_URL ) . ‘/build/myplugin.build.js’, array(
‘wp-components’,
‘wp-blocks’,
‘wp-element’,
‘wp-data’,
‘wp-date’,
‘wp-utils’,
‘wp-i18n’,
), MY_PLUGIN_VERSION );
}
add_action( ‘enqueue_block_assets’, ‘my_plugin_enqueue_editor_assets’ );
The above then will be loaded as separate
Source: https://managewp.org/articles/17174/gutenberg-core-wordpress-libraries-as-es-modules-with-webpack
source https://williechiu40.wordpress.com/2018/02/27/gutenberg-core-wordpress-libraries-as-es-modules-with-webpack/
No comments:
Post a Comment