Skip to content

Commit ebbb074

Browse files
dhasilvaclaude
andcommitted
Build only one variant per mode in wp-build-polyfills
Production builds produce minified files (index.min.js), development builds produce unminified files (index.js). This matches the Jetpack monorepo convention and avoids the waste of building both variants. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f6dd1cf commit ebbb074

File tree

1 file changed

+13
-42
lines changed

1 file changed

+13
-42
lines changed

projects/packages/wp-build-polyfills/bin/build-polyfills.mjs

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -348,37 +348,26 @@ const scriptModulePolyfills = [
348348
const target = [ 'es2020' ];
349349
const builds = [];
350350

351+
// Production builds produce minified files (index.min.js);
352+
// development builds produce unminified files (index.js).
353+
// The PHP registration class selects the appropriate file at runtime
354+
// via SCRIPT_DEBUG, and skips registration if the file doesn't exist.
355+
const outFileName = isProduction ? 'index.min.js' : 'index.js';
356+
351357
for ( const polyfill of classicScriptPolyfills ) {
352358
const outputDir = path.join( outputBase, 'scripts', polyfill.name );
353359

354-
// Minified
355-
builds.push(
356-
build( {
357-
entryPoints: [ polyfill.entry ],
358-
outfile: path.join( outputDir, 'index.min.js' ),
359-
bundle: true,
360-
format: 'iife',
361-
globalName: polyfill.globalName,
362-
target,
363-
platform: 'browser',
364-
minify: true,
365-
sourcemap: isProduction,
366-
plugins: [ polyfillExternalsPlugin( 'iife', polyfill.packageName ) ],
367-
} )
368-
);
369-
370-
// Non-minified
371360
builds.push(
372361
build( {
373362
entryPoints: [ polyfill.entry ],
374-
outfile: path.join( outputDir, 'index.js' ),
363+
outfile: path.join( outputDir, outFileName ),
375364
bundle: true,
376365
format: 'iife',
377366
globalName: polyfill.globalName,
378367
target,
379368
platform: 'browser',
380-
minify: false,
381-
sourcemap: ! isProduction,
369+
minify: isProduction,
370+
sourcemap: true,
382371
plugins: [ polyfillExternalsPlugin( 'iife', polyfill.packageName ) ],
383372
} )
384373
);
@@ -387,34 +376,16 @@ for ( const polyfill of classicScriptPolyfills ) {
387376
for ( const polyfill of scriptModulePolyfills ) {
388377
const outputDir = path.join( outputBase, 'modules', polyfill.name );
389378

390-
const entryPoint = polyfill.entry;
391-
392-
// Minified
393-
builds.push(
394-
build( {
395-
entryPoints: [ entryPoint ],
396-
outfile: path.join( outputDir, 'index.min.js' ),
397-
bundle: true,
398-
format: 'esm',
399-
target,
400-
platform: 'browser',
401-
minify: true,
402-
sourcemap: isProduction,
403-
plugins: [ polyfillExternalsPlugin( 'esm', polyfill.packageName ) ],
404-
} )
405-
);
406-
407-
// Non-minified
408379
builds.push(
409380
build( {
410-
entryPoints: [ entryPoint ],
411-
outfile: path.join( outputDir, 'index.js' ),
381+
entryPoints: [ polyfill.entry ],
382+
outfile: path.join( outputDir, outFileName ),
412383
bundle: true,
413384
format: 'esm',
414385
target,
415386
platform: 'browser',
416-
minify: false,
417-
sourcemap: ! isProduction,
387+
minify: isProduction,
388+
sourcemap: true,
418389
plugins: [ polyfillExternalsPlugin( 'esm', polyfill.packageName ) ],
419390
} )
420391
);

0 commit comments

Comments
 (0)