mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
fix: add nitro client plugin ($fetch support) (#223)
* fix(nuxt3): add nitro client plugin ($fetch support) closes #213 * refactor: put hook in more logical place * docs: update comment
This commit is contained in:
parent
e4bb36883a
commit
e2d5a2f4b3
@ -10,14 +10,15 @@ const commonPlugins = [
|
||||
<%= app.plugins.filter(p => !p.mode || p.mode === 'all').map(p => utils.importName(p.src)).join(',\n ') %>
|
||||
]
|
||||
|
||||
export const clientPluigns = [
|
||||
...commonPlugins,<%= app.plugins.filter(p => p.mode === 'client').map(p => utils.importName(p.src)).join(',\n ') %>
|
||||
export const clientPlugins = [
|
||||
...commonPlugins,
|
||||
<%= app.plugins.filter(p => p.mode === 'client').map(p => utils.importName(p.src)).join(',\n ') %>
|
||||
]
|
||||
|
||||
export const serverPluigns = [
|
||||
export const serverPlugins = [
|
||||
...commonPlugins,
|
||||
preload,
|
||||
<%= app.plugins.filter(p => p.mode === 'server').map(p => utils.importName(p.src)).join(',\n ') %>
|
||||
]
|
||||
|
||||
export default process.client ? clientPluigns : serverPluigns
|
||||
export default process.client ? clientPlugins : serverPlugins
|
||||
|
@ -3,3 +3,5 @@ import { $fetch } from 'ohmyfetch'
|
||||
if (!globalThis.$fetch) {
|
||||
globalThis.$fetch = $fetch
|
||||
}
|
||||
|
||||
export default () => {}
|
||||
|
@ -18,6 +18,11 @@ export function initNitro (nuxt: Nuxt) {
|
||||
nuxt.hooks.addHooks(nitroDevContext.nuxtHooks)
|
||||
nuxt.hook('close', () => nitroDevContext._internal.hooks.callHook('close'))
|
||||
|
||||
// Add nitro client plugin (to inject $fetch helper)
|
||||
nuxt.hook('app:resolve', (app) => {
|
||||
app.plugins.push({ src: require.resolve('@nuxt/nitro/dist/runtime/app/nitro.client') })
|
||||
})
|
||||
|
||||
// Expose process.env.NITRO_PRESET
|
||||
nuxt.options.env.NITRO_PRESET = nitroContext.preset
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user