mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): handle relative baseURL in nitro runtime config (#23841)
This commit is contained in:
parent
f4b7406e10
commit
7b8e7f176d
@ -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<NuxtAppManifest>(joinURL(config.app.cdnURL || config.app.baseURL, config.app.buildAssetsDir, `builds/meta/${buildId}.json`))
|
||||
manifest = $fetch<NuxtAppManifest>(buildAssetsURL(`builds/meta/${buildId}.json`))
|
||||
manifest.then((m) => {
|
||||
matcher = createMatcherFromExport(m.matcher)
|
||||
})
|
||||
|
@ -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<NuxtAppManifestMeta>(joinURL(config.app.cdnURL || config.app.baseURL, config.app.buildAssetsDir, 'builds/latest.json'))
|
||||
const meta = await $fetch<NuxtAppManifestMeta>(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)
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user