Skip to content

Commit

Permalink
refactor example block extensions import
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankaegy committed Aug 24, 2023
1 parent 7205b6e commit 5016b67
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
15 changes: 13 additions & 2 deletions example/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// Useful global constants.
define( 'EXAMPLE_PLUGIN_TEMPLATE_URL', plugin_dir_url( __FILE__ ) );
define( 'EXAMPLE_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'EXAMPLE_PLUGIN_DIST_PATH', EXAMPLE_PLUGIN_PATH . 'dist/' );
define( 'EXAMPLE_PLUGIN_DIST_URL', EXAMPLE_PLUGIN_TEMPLATE_URL . '/dist/' );
define( 'EXAMPLE_PLUGIN_DIST_PATH', EXAMPLE_PLUGIN_PATH . 'build/' );
define( 'EXAMPLE_PLUGIN_DIST_URL', EXAMPLE_PLUGIN_TEMPLATE_URL . '/build/' );
define( 'EXAMPLE_PLUGIN_INC', EXAMPLE_PLUGIN_PATH . 'includes/' );
define( 'EXAMPLE_PLUGIN_BLOCK_DIR', EXAMPLE_PLUGIN_INC . 'blocks/' );
define( 'EXAMPLE_PLUGIN_BLOCK_DIST_DIR', EXAMPLE_PLUGIN_PATH . 'build/blocks/' );
Expand All @@ -28,6 +28,17 @@
* Register the block
*/
function register_block() {

$asset_file = include EXAMPLE_PLUGIN_DIST_PATH . 'index.asset.php';

wp_enqueue_script(
'example-block-editor-script',
EXAMPLE_PLUGIN_DIST_URL . 'index.js',
$asset_file['dependencies'],
$asset_file['version'],
true
);

if ( file_exists( EXAMPLE_PLUGIN_BLOCK_DIST_DIR ) ) {
$block_json_files = glob( EXAMPLE_PLUGIN_BLOCK_DIST_DIR . '*/block.json' );
foreach ( $block_json_files as $filename ) {
Expand Down
13 changes: 0 additions & 13 deletions example/src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
import './blocks/hello-world';
import './extensions/background-pattern';
import './blocks/icon-picker-example';
import './blocks/repeater-component-example';
import './blocks/link-example';
import './blocks/image-example';
import './blocks/content-search-example';
import './blocks/rich-text-character-limit';
import './blocks/post-title';
import './blocks/post-featured-image';
import './blocks/content-item';
import './blocks/hero';
import './blocks/post-meta';
import './blocks/inner-blocks-slider';
9 changes: 9 additions & 0 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

module.exports = {
...defaultConfig,
entry: {
...defaultConfig.entry(),
'index': './src/index.js',
},
};

0 comments on commit 5016b67

Please sign in to comment.