@@ -484,6 +484,21 @@ async function copyFiles(entryPoints, targetDir) {
484484 )
485485}
486486
487+ // In development, create placeholder CSS and sourcemap files to avoid 404 noise
488+ async function ensureDevCssPlaceholders ( targetDir ) {
489+ if ( isProduction ) return
490+ const cssFiles = [ path . join ( targetDir , 'popup.css' ) , path . join ( targetDir , 'content-script.css' ) ]
491+ for ( const cssPath of cssFiles ) {
492+ if ( ! ( await fs . pathExists ( cssPath ) ) ) {
493+ await fs . outputFile ( cssPath , '/* dev placeholder */\n' )
494+ }
495+ const mapPath = `${ cssPath } .map`
496+ if ( ! ( await fs . pathExists ( mapPath ) ) ) {
497+ await fs . outputFile ( mapPath , '{"version":3,"sources":[],"mappings":"","names":[]}' )
498+ }
499+ }
500+ }
501+
487502async function finishOutput ( outputDirSuffix , sourceBuildDir = outdir ) {
488503 const commonFiles = [
489504 { src : 'src/logo.png' , dst : 'logo.png' } ,
@@ -520,22 +535,7 @@ async function finishOutput(outputDirSuffix, sourceBuildDir = outdir) {
520535 [ ...commonFiles , { src : 'src/manifest.json' , dst : 'manifest.json' } ] ,
521536 chromiumOutputDir ,
522537 )
523- // In development, ensure placeholder CSS and CSS sourcemap files exist to avoid 404 noise
524- if ( ! isProduction ) {
525- const chromiumCssPlaceholders = [
526- path . join ( chromiumOutputDir , 'popup.css' ) ,
527- path . join ( chromiumOutputDir , 'content-script.css' ) ,
528- ]
529- for ( const p of chromiumCssPlaceholders ) {
530- if ( ! ( await fs . pathExists ( p ) ) ) {
531- await fs . outputFile ( p , '/* dev placeholder */\n' )
532- }
533- const mapPath = `${ p } .map`
534- if ( ! ( await fs . pathExists ( mapPath ) ) ) {
535- await fs . outputFile ( mapPath , '{"version":3,"sources":[],"mappings":"","names":[]}' )
536- }
537- }
538- }
538+ await ensureDevCssPlaceholders ( chromiumOutputDir )
539539 if ( isProduction ) await zipFolder ( chromiumOutputDir )
540540
541541 // firefox
@@ -544,22 +544,7 @@ async function finishOutput(outputDirSuffix, sourceBuildDir = outdir) {
544544 [ ...commonFiles , { src : 'src/manifest.v2.json' , dst : 'manifest.json' } ] ,
545545 firefoxOutputDir ,
546546 )
547- // In development, ensure placeholder CSS and CSS sourcemap files exist to avoid 404 noise
548- if ( ! isProduction ) {
549- const firefoxCssPlaceholders = [
550- path . join ( firefoxOutputDir , 'popup.css' ) ,
551- path . join ( firefoxOutputDir , 'content-script.css' ) ,
552- ]
553- for ( const p of firefoxCssPlaceholders ) {
554- if ( ! ( await fs . pathExists ( p ) ) ) {
555- await fs . outputFile ( p , '/* dev placeholder */\n' )
556- }
557- const mapPath = `${ p } .map`
558- if ( ! ( await fs . pathExists ( mapPath ) ) ) {
559- await fs . outputFile ( mapPath , '{"version":3,"sources":[],"mappings":"","names":[]}' )
560- }
561- }
562- }
547+ await ensureDevCssPlaceholders ( firefoxOutputDir )
563548 if ( isProduction ) await zipFolder ( firefoxOutputDir )
564549}
565550
0 commit comments