WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/28/2021 10:05:01 AM (4 months ago)
Author:
gziolo
Message:

Build: Split packages and blocks to their webpack configs

It aligns with the changes proposed added in Gutenberg: https://github.com/WordPress/gutenberg/pull/33293.

The idea here is to split the growing webpack config into two parts: blocks and packages.

We need to add handling for JavaScript files that are going to be used with blocks on the frontend. They didn't work quite well with the current setup for entry points created for packages.

As part of the effort, it adds support for viewScript in block.json metadata file that is later translated to $view_script in WP_Block_Type class and exposed as view_script from the REST API endpoint for block types.

Props youknowriad, desrosj, aristath.
Fixes #53690.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block.php

    r51298 r51501  
    230230        }
    231231
     232        if ( ! empty( $this->block_type->view_script ) && empty( $this->block_type->render_callback ) ) {
     233            wp_enqueue_script( $this->block_type->view_script );
     234        }
     235
    232236        if ( ! empty( $this->block_type->style ) ) {
    233237            wp_enqueue_style( $this->block_type->style );
Note: See TracChangeset for help on using the changeset viewer.