Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions packages/wp-build/lib/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,11 +1241,19 @@ async function generatePagesPhp( pageData, replacements ) {
await Promise.all( pageGenerationPromises );

// Generate pages.php loader
const pageIncludes = pageData
.map( ( page ) => {
return `require_once __DIR__ . '/pages/${ page.slug }/page.php';\nrequire_once __DIR__ . '/pages/${ page.slug }/page-wp-admin.php';`;
} )
.join( '\n' );
const pageFiles = pageData.flatMap( ( page ) => [
`\t__DIR__ . '/pages/${ page.slug }/page.php'`,
`\t__DIR__ . '/pages/${ page.slug }/page-wp-admin.php'`,
] );
const pageIncludes = [
'foreach ( [',
pageFiles.join( ',\n' ) + ',',
'] as $file ) {',
'\tif ( file_exists( $file ) ) {',
'\t\trequire_once $file;',
'\t}',
'}',
].join( '\n' );

await generatePhpFromTemplate(
'pages.php.template',
Expand Down
6 changes: 5 additions & 1 deletion packages/wp-build/templates/module-registration.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ function {{PREFIX}}_register_script_modules() {
$already_registered = true;

// Load build constants
$build_constants = require __DIR__ . '/constants.php';
$constants_file = __DIR__ . '/constants.php';
if ( ! file_exists( $constants_file ) ) {
return;
}
$build_constants = require $constants_file;
$modules_dir = __DIR__ . '/modules';
$modules_file = $modules_dir . '/registry.php';

Expand Down
Loading