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/*-rtl.css
/src/wp-admin/css/colors/*/*.css /src/wp-admin/css/colors/*/*.css
/src/wp-admin/js /src/wp-admin/js
/src/wp-includes/assets
/src/wp-includes/js /src/wp-includes/js
/src/wp-includes/css/dist /src/wp-includes/css/dist
/src/wp-includes/css/*.min.css /src/wp-includes/css/*.min.css

View File

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

6
package-lock.json generated
View File

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

View File

@ -26,7 +26,7 @@
], ],
"devDependencies": { "devDependencies": {
"@wordpress/custom-templated-path-webpack-plugin": "1.6.0", "@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/e2e-test-utils": "4.3.0",
"@wordpress/library-export-default-webpack-plugin": "1.6.0", "@wordpress/library-export-default-webpack-plugin": "1.6.0",
"@wordpress/scripts": "6.2.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 ) { function wp_default_packages_scripts( &$scripts ) {
$suffix = wp_scripts_get_suffix(); $suffix = wp_scripts_get_suffix();
$packages = array( // Expects multidimensional array like:
'a11y', // 'a11y.js' => array('dependencies' => array(...), 'version' => '...'),
'annotations', // 'annotations.js' => array('dependencies' => array(...), 'version' => '...'),
'api-fetch', // 'api-fetch.js' => array(...
'autop', $assets = include ABSPATH . WPINC . '/assets/script-loader-packages.php';
'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',
);
$package_translations = array( foreach ( $assets as $package_name => $package_data ) {
'api-fetch', $basename = basename( $package_name, '.js' );
'blocks', $handle = 'wp-' . $basename;
'block-directory', $path = "/wp-includes/js/dist/{$basename}{$suffix}.js";
'block-editor',
'block-library',
'components',
'edit-post',
'editor',
'format-library',
'keycodes',
'list-reusable-blocks',
'nux',
);
foreach ( $packages as $package ) { if ( ! empty( $package_data['dependencies'] ) ) {
$handle = 'wp-' . $package; $dependencies = $package_data['dependencies'];
$path = "/wp-includes/js/dist/$package$suffix.js"; } else {
$dependencies = array();
if ( ! file_exists( ABSPATH . $path ) ) {
continue;
} }
$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. // Add dependencies that cannot be detected and generated by build tools.
switch ( $handle ) { switch ( $handle ) {
case 'wp-block-library': case 'wp-block-library':
@ -316,9 +258,9 @@ function wp_default_packages_scripts( &$scripts ) {
break; 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 ); $scripts->set_translations( $handle );
} }
} }

View File

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