Skip to content

Commit f9549b6

Browse files
Derive dev CSS placeholders from output list
Reuse the destination entries we already compute to decide which CSS assets need development placeholders, eliminating hard-coded filenames flagged in review.
1 parent dec9a16 commit f9549b6

1 file changed

Lines changed: 31 additions & 14 deletions

File tree

build.mjs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -529,18 +529,19 @@ async function copyFiles(entryPoints, targetDir) {
529529
}
530530

531531
// In development, create placeholder CSS and sourcemap files to avoid 404 noise
532-
async function ensureDevCssPlaceholders(targetDir) {
533-
if (isProduction) return
534-
const cssFiles = [path.join(targetDir, 'popup.css'), path.join(targetDir, 'content-script.css')]
535-
for (const cssPath of cssFiles) {
536-
if (!(await fs.pathExists(cssPath))) {
537-
await fs.outputFile(cssPath, '/* dev placeholder */\n')
538-
}
539-
const mapPath = `${cssPath}.map`
540-
if (!(await fs.pathExists(mapPath))) {
541-
await fs.outputFile(mapPath, '{"version":3,"sources":[],"mappings":"","names":[]}')
542-
}
543-
}
532+
async function ensureDevCssPlaceholders(cssFiles) {
533+
if (isProduction || cssFiles.length === 0) return
534+
await Promise.all(
535+
cssFiles.map(async (cssPath) => {
536+
if (!(await fs.pathExists(cssPath))) {
537+
await fs.outputFile(cssPath, '/* dev placeholder */\n')
538+
}
539+
const mapPath = `${cssPath}.map`
540+
if (!(await fs.pathExists(mapPath))) {
541+
await fs.outputFile(mapPath, '{"version":3,"sources":[],"mappings":"","names":[]}')
542+
}
543+
}),
544+
)
544545
}
545546

546547
async function finishOutput(outputDirSuffix, sourceBuildDir = outdir) {
@@ -579,7 +580,15 @@ async function finishOutput(outputDirSuffix, sourceBuildDir = outdir) {
579580
[...commonFiles, { src: 'src/manifest.json', dst: 'manifest.json' }],
580581
chromiumOutputDir,
581582
)
582-
await ensureDevCssPlaceholders(chromiumOutputDir)
583+
await ensureDevCssPlaceholders(
584+
Array.from(
585+
new Set(
586+
commonFiles
587+
.filter((file) => file.dst.endsWith('.css'))
588+
.map((file) => path.join(chromiumOutputDir, file.dst)),
589+
),
590+
),
591+
)
583592
if (isProduction) await zipFolder(chromiumOutputDir)
584593

585594
// firefox
@@ -588,7 +597,15 @@ async function finishOutput(outputDirSuffix, sourceBuildDir = outdir) {
588597
[...commonFiles, { src: 'src/manifest.v2.json', dst: 'manifest.json' }],
589598
firefoxOutputDir,
590599
)
591-
await ensureDevCssPlaceholders(firefoxOutputDir)
600+
await ensureDevCssPlaceholders(
601+
Array.from(
602+
new Set(
603+
commonFiles
604+
.filter((file) => file.dst.endsWith('.css'))
605+
.map((file) => path.join(firefoxOutputDir, file.dst)),
606+
),
607+
),
608+
)
592609
if (isProduction) await zipFolder(firefoxOutputDir)
593610
}
594611

0 commit comments

Comments
 (0)