diff --git a/packages/nuxt/src/app/composables/manifest.ts b/packages/nuxt/src/app/composables/manifest.ts index 0fc9cec5aa..39d94590ff 100644 --- a/packages/nuxt/src/app/composables/manifest.ts +++ b/packages/nuxt/src/app/composables/manifest.ts @@ -1,10 +1,11 @@ -import { joinURL } from 'ufo' import type { MatcherExport, RouteMatcher } from 'radix3' import { createMatcherFromExport } from 'radix3' import { defu } from 'defu' -import { useAppConfig, useRuntimeConfig } from '#app' +import { useAppConfig } from '#app' // @ts-expect-error virtual file import { appManifest as isAppManifestEnabled } from '#build/nuxt.config.mjs' +// @ts-expect-error virtual file +import { buildAssetsURL } from '#build/paths.mjs' export interface NuxtAppManifestMeta { id: string @@ -23,10 +24,9 @@ function fetchManifest () { if (!isAppManifestEnabled) { throw new Error('[nuxt] app manifest should be enabled with `experimental.appManifest`') } - const config = useRuntimeConfig() // @ts-expect-error private property const buildId = useAppConfig().nuxt?.buildId - manifest = $fetch(joinURL(config.app.cdnURL || config.app.baseURL, config.app.buildAssetsDir, `builds/meta/${buildId}.json`)) + manifest = $fetch(buildAssetsURL(`builds/meta/${buildId}.json`)) manifest.then((m) => { matcher = createMatcherFromExport(m.matcher) }) diff --git a/packages/nuxt/src/app/plugins/check-outdated-build.client.ts b/packages/nuxt/src/app/plugins/check-outdated-build.client.ts index 27561909ad..6d03078f23 100644 --- a/packages/nuxt/src/app/plugins/check-outdated-build.client.ts +++ b/packages/nuxt/src/app/plugins/check-outdated-build.client.ts @@ -1,18 +1,18 @@ -import { joinURL } from 'ufo' import type { NuxtAppManifestMeta } from '#app' -import { defineNuxtPlugin, getAppManifest, onNuxtReady, useRuntimeConfig } from '#app' +import { defineNuxtPlugin, getAppManifest, onNuxtReady } from '#app' +// @ts-expect-error virtual file +import { buildAssetsURL } from '#build/paths.mjs' export default defineNuxtPlugin((nuxtApp) => { if (import.meta.test) { return } let timeout: NodeJS.Timeout - const config = useRuntimeConfig() async function getLatestManifest () { const currentManifest = await getAppManifest() if (timeout) { clearTimeout(timeout) } timeout = setTimeout(getLatestManifest, 1000 * 60 * 60) - const meta = await $fetch(joinURL(config.app.cdnURL || config.app.baseURL, config.app.buildAssetsDir, 'builds/latest.json')) + const meta = await $fetch(buildAssetsURL('builds/latest.json')) if (meta.id !== currentManifest.id) { // There is a newer build which we will let the user handle nuxtApp.hooks.callHook('app:manifest:update', meta) diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index bd9161666e..6495b20d0b 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -11,7 +11,7 @@ import escapeRE from 'escape-string-regexp' import { defu } from 'defu' import fsExtra from 'fs-extra' import { dynamicEventHandler } from 'h3' -import type { Nuxt } from 'nuxt/schema' +import type { Nuxt, RuntimeConfig } from 'nuxt/schema' // @ts-expect-error TODO: add legacy type support for subpath imports import { template as defaultSpaLoadingTemplate } from '@nuxt/ui-templates/templates/spa-loading-icon.mjs' @@ -99,6 +99,12 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { }, runtimeConfig: { ...nuxt.options.runtimeConfig, + app: { + ...nuxt.options.runtimeConfig.app, + baseURL: nuxt.options.runtimeConfig.app.baseURL.startsWith('./') + ? nuxt.options.runtimeConfig.app.baseURL.slice(1) + : nuxt.options.runtimeConfig.app.baseURL + } satisfies RuntimeConfig['app'], nitro: { envPrefix: 'NUXT_', ...nuxt.options.runtimeConfig.nitro diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 7d57f2e8e3..95e65e3685 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -19,7 +19,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM for (const outputDir of ['.output', '.output-inline']) { it('default client bundle size', async () => { const clientStats = await analyzeSizes('**/*.js', join(rootDir, outputDir, 'public')) - expect.soft(roundToKilobytes(clientStats.totalBytes)).toMatchInlineSnapshot('"99.3k"') + expect.soft(roundToKilobytes(clientStats.totalBytes)).toMatchInlineSnapshot('"99.2k"') expect(clientStats.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(` [ "_nuxt/entry.js",