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> const pageMetaMap = Object.create(null) as Record<string, PageMeta>
try { 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) { if (process.env.BUNDLE_ONLY) {
return 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) await siteConfig.buildEnd?.(siteConfig)
clearCache() clearCache()

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

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

Loading…
Cancel
Save