refactor(build): own all task spinners in build()

bundle() and generateSitemap() are plain workers now; build() wraps
them in tasks alongside render. Keeps the MPA asset copies and the
MPA client build under the bundles spinner instead of running after
it resolves, and skips the sitemap spinner when sitemap generation
is off.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
pull/5342/head
Divyansh Singh 1 month ago
parent 9dfa3bf524
commit a53982f937

@ -56,7 +56,10 @@ export async function build(
const pageMetaMap = Object.create(null) as Record<string, PageMeta>
try {
const out = await bundle(siteConfig, buildOptions, pageMetaMap)
const out = await task(
'building client + server bundles',
bundle.bind(null, siteConfig, buildOptions, pageMetaMap)
)
if (process.env.BUNDLE_ONLY) {
return
@ -74,7 +77,13 @@ export async function build(
}
}
await generateSitemap(siteConfig, pageMetaMap)
if (siteConfig.sitemap?.hostname) {
await task(
'generating sitemap',
generateSitemap.bind(null, siteConfig, pageMetaMap)
)
}
await siteConfig.buildEnd?.(siteConfig)
clearCache()

@ -14,7 +14,6 @@ import { APP_PATH } from '../alias'
import type { SiteConfig } from '../config'
import { createVitePressPlugin, type PageMeta } from '../plugin'
import { escapeRegExp, sanitizeFileName, slash } from '../shared'
import { task } from '../utils/task'
import { buildMPAClient } from './buildMPAClient'
// https://github.com/vitejs/vite/blob/a55d0b34400e3360c4100d05e422ae9cf10fa07b/packages/vite/src/node/constants.ts#L50
@ -135,20 +134,12 @@ export async function bundle(
configFile: config.vite?.configFile
})
let { clientResult, serverResult } = await task(
'building client + server bundles',
async () => {
const clientResult = config.mpa
let clientResult = config.mpa
? null
: ((await build(
await resolveViteConfig(false)
)) as Rolldown.RolldownOutput)
: ((await build(await resolveViteConfig(false))) as Rolldown.RolldownOutput)
const serverResult = (await build(
await resolveViteConfig(true)
)) as Rolldown.RolldownOutput
return { clientResult, serverResult }
}
)
if (config.mpa) {
// in MPA mode, we need to copy over the non-js asset files from the

@ -10,15 +10,11 @@ import {
} from 'sitemap'
import type { SiteConfig } from '../config'
import type { PageMeta } from '../plugin'
import { task } from '../utils/task'
export async function generateSitemap(
siteConfig: SiteConfig,
pageMetaMap: Record<string, PageMeta>
) {
if (!siteConfig.sitemap?.hostname) return
await task('generating sitemap', async () => {
const locales = siteConfig.userConfig.locales || {}
const defaultLang =
locales.root?.lang || siteConfig.userConfig.lang || 'en-US'
@ -71,7 +67,6 @@ export async function generateSitemap(
items.forEach((item) => sitemapStream.write(item))
sitemapStream.end()
await pipeline(sitemapStream, fs.createWriteStream(sitemapPath))
})
}
// ============================== Patched Types ===============================

Loading…
Cancel
Save