diff --git a/lib/client-assets.php b/lib/client-assets.php index f95ac27f81d010..8b0fab794cf994 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -617,6 +617,7 @@ function gutenberg_register_vendor_scripts( $scripts ) { * @since 19.3.0 */ function gutenberg_default_script_modules() { + $suffix = wp_scripts_get_suffix(); /* * Expects multidimensional array like: * @@ -624,7 +625,7 @@ function gutenberg_default_script_modules() { * 'interactivity/debug.min.js' => array('dependencies' => array(…), 'version' => '…'), * 'interactivity-router/index.min.js' => … */ - $assets = include gutenberg_dir_path() . '/build-module/assets.php'; + $assets = include gutenberg_dir_path() . "/build-module/assets{$suffix}.php"; foreach ( $assets as $file_name => $script_module_data ) { /* @@ -634,7 +635,7 @@ function gutenberg_default_script_modules() { * - interactivity/debug.min.js => @wordpress/interactivity/debug * - block-library/query/view.js => @wordpress/block-library/query/view */ - $script_module_id = '@wordpress/' . preg_replace( '~(?:/index)?\.min\.js$~D', '', $file_name, 1 ); + $script_module_id = '@wordpress/' . preg_replace( '~(?:/index)?(?:\.min)?\.js$~D', '', $file_name, 1 ); switch ( $script_module_id ) { /* * Interactivity exposes two entrypoints, "/index" and "/debug". diff --git a/tools/webpack/script-modules.js b/tools/webpack/script-modules.js index aac387ee32957a..3792c7df45c8fb 100644 --- a/tools/webpack/script-modules.js +++ b/tools/webpack/script-modules.js @@ -66,38 +66,42 @@ for ( const packageDir of packageDirs ) { ); } } +module.exports = function () { + const suffix = baseConfig.mode === 'production' ? '.min' : ''; -module.exports = { - ...baseConfig, - name: 'script-modules', - entry: Object.fromEntries( gutenbergScriptModules.entries() ), - experiments: { - outputModule: true, - }, - output: { - devtoolNamespace: 'wp', - filename: '[name].min.js', - library: { - type: 'module', + const config = { + ...baseConfig, + name: 'script-modules', + entry: Object.fromEntries( gutenbergScriptModules.entries() ), + experiments: { + outputModule: true, }, - path: join( __dirname, '..', '..', 'build-module' ), - environment: { module: true }, - module: true, - chunkFormat: 'module', - asyncChunks: false, - }, - resolve: { - extensions: [ '.js', '.ts', '.tsx' ], - }, - plugins: [ - ...plugins, - new DependencyExtractionWebpackPlugin( { - combineAssets: true, - combinedOutputFile: `./assets.php`, - } ), - ], - watchOptions: { - ignored: [ '**/node_modules' ], - aggregateTimeout: 500, - }, + output: { + devtoolNamespace: 'wp', + filename: `[name]${ suffix }.js`, + library: { + type: 'module', + }, + path: join( __dirname, '..', '..', 'build-module' ), + environment: { module: true }, + module: true, + chunkFormat: 'module', + asyncChunks: false, + }, + resolve: { + extensions: [ '.js', '.ts', '.tsx' ], + }, + plugins: [ + ...plugins, + new DependencyExtractionWebpackPlugin( { + combineAssets: true, + combinedOutputFile: `./assets${ suffix }.php`, + } ), + ], + watchOptions: { + ignored: [ '**/node_modules' ], + aggregateTimeout: 500, + }, + }; + return config; };