mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build: Prepare for more Script Modules
This is a companion to WordPress/gutenberg#65460 that requires syncing in WordPress Core. Namely, the block-library changes require registration with their updated script module IDs so that the blocks continue to work correctly. They key improvement is script modules registration is handled in one central place, and a combined asset file is used to improve the performance by avoiding multiple disk operations for every individual file. Props jonsurrell, gziolo, wildworks, noisysocks. See #60647, #59462. git-svn-id: https://develop.svn.wordpress.org/trunk@59083 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
Showing
11 changed files
with
193 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('interactivity/index.min.js' => array('dependencies' => array(), 'version' => '2d6d1fdbcb3fda39c768', 'type' => 'module'), 'interactivity/debug.min.js' => array('dependencies' => array(), 'version' => '1ccc67b05c275e51a8f8', 'type' => 'module'), 'interactivity-router/index.min.js' => array('dependencies' => array('@wordpress/interactivity'), 'version' => '64645ef3cd2d32860d7d', 'type' => 'module'), 'block-library/file/view.min.js' => array('dependencies' => array('@wordpress/interactivity'), 'version' => 'fdc2f6842e015af83140', 'type' => 'module'), 'block-library/image/view.min.js' => array('dependencies' => array('@wordpress/interactivity'), 'version' => 'acfec7b3c0be4a859b31', 'type' => 'module'), 'block-library/navigation/view.min.js' => array('dependencies' => array('@wordpress/interactivity'), 'version' => '8ff192874fc8910a284c', 'type' => 'module'), 'block-library/query/view.min.js' => array('dependencies' => array('@wordpress/interactivity', array('id' => '@wordpress/interactivity-router', 'import' => 'dynamic')), 'version' => 'f4c91c89fa5271f3dad9', 'type' => 'module'), 'block-library/search/view.min.js' => array('dependencies' => array('@wordpress/interactivity'), 'version' => '2a73400a693958f604de', 'type' => 'module')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const { createRequire } = require( 'node:module' ); | ||
const { dirname } = require( 'node:path' ); | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
const DependencyExtractionPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const { | ||
baseDir, | ||
getBaseConfig, | ||
normalizeJoin, | ||
MODULES, | ||
SCRIPT_AND_MODULE_DUAL_PACKAGES, | ||
WORDPRESS_NAMESPACE, | ||
} = require( './shared' ); | ||
|
||
/** @type {Map<string, string>} */ | ||
const scriptModules = new Map(); | ||
for ( const packageName of MODULES.concat( SCRIPT_AND_MODULE_DUAL_PACKAGES ) ) { | ||
const packageRequire = createRequire( | ||
`${ dirname( require.resolve( `${ packageName }/package.json` ) ) }/` | ||
); | ||
|
||
const depPackageJson = packageRequire( './package.json' ); | ||
if ( ! Object.hasOwn( depPackageJson, 'wpScriptModuleExports' ) ) { | ||
continue; | ||
} | ||
|
||
const moduleName = packageName.substring( WORDPRESS_NAMESPACE.length ); | ||
let { wpScriptModuleExports } = depPackageJson; | ||
|
||
// Special handling for { "wpScriptModuleExports": "./build-module/index.js" }. | ||
if ( typeof wpScriptModuleExports === 'string' ) { | ||
wpScriptModuleExports = { '.': wpScriptModuleExports }; | ||
} | ||
|
||
if ( Object.getPrototypeOf( wpScriptModuleExports ) !== Object.prototype ) { | ||
throw new Error( 'wpScriptModuleExports must be an object' ); | ||
} | ||
|
||
for ( const [ exportName, exportPath ] of Object.entries( | ||
wpScriptModuleExports | ||
) ) { | ||
if ( typeof exportPath !== 'string' ) { | ||
throw new Error( 'wpScriptModuleExports paths must be strings' ); | ||
} | ||
|
||
if ( ! exportPath.startsWith( './' ) ) { | ||
throw new Error( | ||
'wpScriptModuleExports paths must start with "./"' | ||
); | ||
} | ||
|
||
const name = | ||
exportName === '.' ? 'index' : exportName.replace( /^\.\/?/, '' ); | ||
|
||
scriptModules.set( | ||
`${ moduleName }/${ name }`, | ||
packageRequire.resolve( exportPath ) | ||
); | ||
} | ||
} | ||
|
||
module.exports = function ( | ||
env = { environment: 'production', watch: false, buildTarget: false } | ||
) { | ||
const mode = env.environment; | ||
const suffix = mode === 'production' ? '.min' : ''; | ||
let buildTarget = env.buildTarget | ||
? env.buildTarget | ||
: mode === 'production' | ||
? 'build' | ||
: 'src'; | ||
buildTarget = buildTarget + '/wp-includes'; | ||
|
||
const baseConfig = getBaseConfig( env ); | ||
const config = { | ||
...baseConfig, | ||
entry: Object.fromEntries( scriptModules.entries() ), | ||
experiments: { | ||
outputModule: true, | ||
}, | ||
output: { | ||
devtoolNamespace: 'wp', | ||
filename: `[name]${ suffix }.js`, | ||
path: normalizeJoin( | ||
baseDir, | ||
`${ buildTarget }/js/dist/script-modules` | ||
), | ||
library: { | ||
type: 'module', | ||
}, | ||
environment: { module: true }, | ||
module: true, | ||
chunkFormat: 'module', | ||
asyncChunks: false, | ||
}, | ||
plugins: [ | ||
...baseConfig.plugins, | ||
new DependencyExtractionPlugin( { | ||
injectPolyfill: false, | ||
combineAssets: true, | ||
combinedOutputFile: normalizeJoin( | ||
baseDir, | ||
`${ buildTarget }/assets/script-modules-packages${ suffix }.php` | ||
), | ||
} ), | ||
], | ||
}; | ||
|
||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters