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.

git-svn-id: https://develop.svn.wordpress.org/trunk@47352 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2020-02-24 21:20:49 +00:00
parent 4e18f78ced
commit b2d243fbe6
7 changed files with 32 additions and 83 deletions

1
.gitignore vendored
View File

@ -24,7 +24,6 @@ wp-tests-config.php
/src/wp-admin/css/*-rtl.css
/src/wp-admin/css/colors/*/*.css
/src/wp-admin/js
/src/wp-includes/assets
/src/wp-includes/js
/src/wp-includes/css/dist
/src/wp-includes/css/*.min.css

View File

@ -117,7 +117,7 @@ module.exports = function(grunt) {
WORKING_DIR + 'wp-includes/js/'
],
'webpack-assets': [
WORKING_DIR + 'wp-includes/js/**/*.asset.php'
WORKING_DIR + 'wp-includes/js/dist/assets.php'
],
dynamic: {
dot: true,
@ -356,10 +356,16 @@ module.exports = function(grunt) {
]
},
'webpack-assets': {
expand: true,
cwd: WORKING_DIR + 'wp-includes/js/',
src: 'dist/*.asset.php',
dest: WORKING_DIR + 'wp-includes/assets/'
files: [
{
src: WORKING_DIR + 'wp-includes/js/dist/assets.php',
dest: SOURCE_DIR + 'wp-includes/assets/script-loader-packages.php'
},
{
src: WORKING_DIR + 'wp-includes/js/dist/assets.php',
dest: BUILD_DIR + 'wp-includes/assets/script-loader-packages.php'
}
]
},
version: {
options: {

6
package-lock.json generated
View File

@ -2525,9 +2525,9 @@
}
},
"@wordpress/dependency-extraction-webpack-plugin": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@wordpress/dependency-extraction-webpack-plugin/-/dependency-extraction-webpack-plugin-2.2.0.tgz",
"integrity": "sha512-74zJPfSohTfcNtNG/Y0VmE/ow1sG6wCEl7A7xN3VdhMRFUOfpfGV2XifBA9UjDoxY/IAbf80WDqiuA7MzcDMKw==",
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/@wordpress/dependency-extraction-webpack-plugin/-/dependency-extraction-webpack-plugin-2.3.0.tgz",
"integrity": "sha512-FwEN0PuFr3Q5IdDLgerkIspiHkePNbzem71R3RlUevaSmnw+iH9/0Jzg4uIQ8KCMBpbrn1gAmhgdaTgTDn3EfQ==",
"dev": true,
"requires": {
"json2php": "^0.0.4",

View File

@ -26,7 +26,7 @@
],
"devDependencies": {
"@wordpress/custom-templated-path-webpack-plugin": "1.6.0",
"@wordpress/dependency-extraction-webpack-plugin": "2.2.0",
"@wordpress/dependency-extraction-webpack-plugin": "2.3.0",
"@wordpress/e2e-test-utils": "4.3.0",
"@wordpress/library-export-default-webpack-plugin": "1.6.0",
"@wordpress/scripts": "6.2.0",

File diff suppressed because one or more lines are too long

View File

@ -231,81 +231,23 @@ function wp_get_script_polyfill( &$scripts, $tests ) {
function wp_default_packages_scripts( &$scripts ) {
$suffix = wp_scripts_get_suffix();
$packages = array(
'a11y',
'annotations',
'api-fetch',
'autop',
'blob',
'block-directory',
'block-editor',
'block-library',
'block-serialization-default-parser',
'blocks',
'components',
'compose',
'core-data',
'data',
'data-controls',
'date',
'deprecated',
'dom',
'dom-ready',
'edit-post',
'editor',
'element',
'escape-html',
'format-library',
'hooks',
'html-entities',
'i18n',
'is-shallow-equal',
'keyboard-shortcuts',
'keycodes',
'list-reusable-blocks',
'media-utils',
'notices',
'nux',
'plugins',
'primitives',
'priority-queue',
'redux-routine',
'rich-text',
'shortcode',
'server-side-render',
'token-list',
'url',
'viewport',
'warning',
'wordcount',
);
// Expects multidimensional array like:
// 'a11y.js' => array('dependencies' => array(...), 'version' => '...'),
// 'annotations.js' => array('dependencies' => array(...), 'version' => '...'),
// 'api-fetch.js' => array(...
$assets = include ABSPATH . WPINC . '/assets/script-loader-packages.php';
$package_translations = array(
'api-fetch',
'blocks',
'block-directory',
'block-editor',
'block-library',
'components',
'edit-post',
'editor',
'format-library',
'keycodes',
'list-reusable-blocks',
'nux',
);
foreach ( $assets as $package_name => $package_data ) {
$basename = basename( $package_name, '.js' );
$handle = 'wp-' . $basename;
$path = "/wp-includes/js/dist/{$basename}{$suffix}.js";
foreach ( $packages as $package ) {
$handle = 'wp-' . $package;
$path = "/wp-includes/js/dist/$package$suffix.js";
if ( ! file_exists( ABSPATH . $path ) ) {
continue;
if ( ! empty( $package_data['dependencies'] ) ) {
$dependencies = $package_data['dependencies'];
} else {
$dependencies = array();
}
$asset_file = require ABSPATH . WPINC . "/assets/dist/$package$suffix.asset.php";
$dependencies = $asset_file['dependencies'];
// Add dependencies that cannot be detected and generated by build tools.
switch ( $handle ) {
case 'wp-block-library':
@ -316,9 +258,9 @@ function wp_default_packages_scripts( &$scripts ) {
break;
}
$scripts->add( $handle, $path, $dependencies, $asset_file['version'], 1 );
$scripts->add( $handle, $path, $dependencies, $package_data['version'], 1 );
if ( in_array( $package, $package_translations, true ) ) {
if ( in_array( 'wp-i18n', $dependencies, true ) ) {
$scripts->set_translations( $handle );
}
}

View File

@ -246,6 +246,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil
} ),
new DependencyExtractionPlugin( {
injectPolyfill: true,
combineAssets: true,
} ),
new CopyWebpackPlugin(
[