Make WordPress Core


Ignore:
Timestamp:
02/24/2020 09:20:49 PM (6 years ago)
Author:
azaozz
Message:

Build Tools:

  • Update the DependencyExtractionWebpackPlugin to 2.3.0 and set it to output a single assets file.
  • Grunt: copy the assets file to both SOURCE_DIR and BUILD_DIR as wp-includes/assets/script-loader-packages.php.
  • "Unignore" the wp-includes/assets directory. Its content will be committed similarly to wp-includes/blocks.
  • Update wp_default_packages_scripts() to use the above file. This also removes the hard-coded lists of packages and packages with translations.

Props gziolo, pbearne, johnbillion, isabel_brison, ocean90, azaozz.
Fixes #48154.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes

    • Property svn:ignore
      •  

        old new  
        1 assets
         1
        22js
  • trunk/src/wp-includes/script-loader.php

    r47259 r47352  
    232232        $suffix = wp_scripts_get_suffix();
    233233
    234         $packages = array(
    235                 'a11y',
    236                 'annotations',
    237                 'api-fetch',
    238                 'autop',
    239                 'blob',
    240                 'block-directory',
    241                 'block-editor',
    242                 'block-library',
    243                 'block-serialization-default-parser',
    244                 'blocks',
    245                 'components',
    246                 'compose',
    247                 'core-data',
    248                 'data',
    249                 'data-controls',
    250                 'date',
    251                 'deprecated',
    252                 'dom',
    253                 'dom-ready',
    254                 'edit-post',
    255                 'editor',
    256                 'element',
    257                 'escape-html',
    258                 'format-library',
    259                 'hooks',
    260                 'html-entities',
    261                 'i18n',
    262                 'is-shallow-equal',
    263                 'keyboard-shortcuts',
    264                 'keycodes',
    265                 'list-reusable-blocks',
    266                 'media-utils',
    267                 'notices',
    268                 'nux',
    269                 'plugins',
    270                 'primitives',
    271                 'priority-queue',
    272                 'redux-routine',
    273                 'rich-text',
    274                 'shortcode',
    275                 'server-side-render',
    276                 'token-list',
    277                 'url',
    278                 'viewport',
    279                 'warning',
    280                 'wordcount',
    281         );
    282 
    283         $package_translations = array(
    284                 'api-fetch',
    285                 'blocks',
    286                 'block-directory',
    287                 'block-editor',
    288                 'block-library',
    289                 'components',
    290                 'edit-post',
    291                 'editor',
    292                 'format-library',
    293                 'keycodes',
    294                 'list-reusable-blocks',
    295                 'nux',
    296         );
    297 
    298         foreach ( $packages as $package ) {
    299                 $handle = 'wp-' . $package;
    300                 $path   = "/wp-includes/js/dist/$package$suffix.js";
    301 
    302                 if ( ! file_exists( ABSPATH . $path ) ) {
    303                         continue;
    304                 }
    305 
    306                 $asset_file   = require ABSPATH . WPINC . "/assets/dist/$package$suffix.asset.php";
    307                 $dependencies = $asset_file['dependencies'];
     234        // Expects multidimensional array like:
     235        //      'a11y.js' => array('dependencies' => array(...), 'version' => '...'),
     236        //      'annotations.js' => array('dependencies' => array(...), 'version' => '...'),
     237        //      'api-fetch.js' => array(...
     238        $assets = include ABSPATH . WPINC . '/assets/script-loader-packages.php';
     239
     240        foreach ( $assets as $package_name => $package_data ) {
     241                $basename = basename( $package_name, '.js' );
     242                $handle   = 'wp-' . $basename;
     243                $path     = "/wp-includes/js/dist/{$basename}{$suffix}.js";
     244
     245                if ( ! empty( $package_data['dependencies'] ) ) {
     246                        $dependencies = $package_data['dependencies'];
     247                } else {
     248                        $dependencies = array();
     249                }
    308250
    309251                // Add dependencies that cannot be detected and generated by build tools.
     
    317259                }
    318260
    319                 $scripts->add( $handle, $path, $dependencies, $asset_file['version'], 1 );
    320 
    321                 if ( in_array( $package, $package_translations, true ) ) {
     261                $scripts->add( $handle, $path, $dependencies, $package_data['version'], 1 );
     262
     263                if ( in_array( 'wp-i18n', $dependencies, true ) ) {
    322264                        $scripts->set_translations( $handle );
    323265                }
Note: See TracChangeset for help on using the changeset viewer.