mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nuxt): init $fetch
at entry start (#23906)
This commit is contained in:
parent
bd86e26763
commit
8c77ce81b9
@ -1,11 +1,9 @@
|
|||||||
// We set __webpack_public_path via this import with webpack builder
|
// We set __webpack_public_path via this import with webpack builder
|
||||||
import { createApp, createSSRApp, nextTick } from 'vue'
|
import { createApp, createSSRApp, nextTick } from 'vue'
|
||||||
import { $fetch } from 'ofetch'
|
|
||||||
import type { $Fetch, NitroFetchRequest } from 'nitropack'
|
|
||||||
|
|
||||||
// This file must be imported first for webpack as we set __webpack_public_path__ there
|
// These files must be imported first as they have side effects
|
||||||
// @ts-expect-error virtual file
|
import '#build/paths.mjs'
|
||||||
import { baseURL } from '#build/paths.mjs'
|
import '#build/fetch.mjs'
|
||||||
|
|
||||||
import type { CreateOptions } from '#app'
|
import type { CreateOptions } from '#app'
|
||||||
import { applyPlugins, createNuxtApp } from '#app/nuxt'
|
import { applyPlugins, createNuxtApp } from '#app/nuxt'
|
||||||
@ -18,12 +16,6 @@ import RootComponent from '#build/root-component.mjs'
|
|||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { vueAppRootContainer } from '#build/nuxt.config.mjs'
|
import { vueAppRootContainer } from '#build/nuxt.config.mjs'
|
||||||
|
|
||||||
if (!globalThis.$fetch) {
|
|
||||||
globalThis.$fetch = $fetch.create({
|
|
||||||
baseURL: baseURL()
|
|
||||||
}) as $Fetch<unknown, NitroFetchRequest>
|
|
||||||
}
|
|
||||||
|
|
||||||
let entry: Function
|
let entry: Function
|
||||||
|
|
||||||
if (import.meta.server) {
|
if (import.meta.server) {
|
||||||
|
@ -334,6 +334,21 @@ export const publicPathTemplate: NuxtTemplate = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const dollarFetchTemplate: NuxtTemplate = {
|
||||||
|
filename: 'fetch.mjs',
|
||||||
|
getContents () {
|
||||||
|
return [
|
||||||
|
"import { $fetch } from 'ofetch'",
|
||||||
|
"import { baseURL } from '#build/paths.mjs'",
|
||||||
|
'if (!globalThis.$fetch) {',
|
||||||
|
' globalThis.$fetch = $fetch.create({',
|
||||||
|
' baseURL: baseURL()',
|
||||||
|
' })',
|
||||||
|
'}'
|
||||||
|
].join('\n')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Allow direct access to specific exposed nuxt.config
|
// Allow direct access to specific exposed nuxt.config
|
||||||
export const nuxtConfigTemplate = {
|
export const nuxtConfigTemplate = {
|
||||||
filename: 'nuxt.config.mjs',
|
filename: 'nuxt.config.mjs',
|
||||||
|
Loading…
Reference in New Issue
Block a user