mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
perf(nuxt): use granular imports for auto-importing composables (#23951)
This commit is contained in:
parent
27791f4c33
commit
d7b1116443
@ -70,6 +70,11 @@
|
|||||||
"target": "packages/nuxt/src/app",
|
"target": "packages/nuxt/src/app",
|
||||||
"message": "app should not directly import from modules."
|
"message": "app should not directly import from modules."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"from": "packages/nuxt/src/app/**/index.ts",
|
||||||
|
"target": "packages/nuxt/src",
|
||||||
|
"message": "should not import from barrel/index files"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"from": "packages/nitro",
|
"from": "packages/nitro",
|
||||||
"target": "packages/!(nitro)/**/*",
|
"target": "packages/!(nitro)/**/*",
|
||||||
|
@ -112,7 +112,7 @@ export default defineNuxtModule({
|
|||||||
|
|
||||||
```ts [plugin.ts]
|
```ts [plugin.ts]
|
||||||
import { createHead as createClientHead, createServerHead } from '@unhead/vue'
|
import { createHead as createClientHead, createServerHead } from '@unhead/vue'
|
||||||
import { defineNuxtPlugin } from '#app'
|
import { defineNuxtPlugin } from '#imports'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import metaConfig from '#build/meta.config.mjs'
|
import metaConfig from '#build/meta.config.mjs'
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ export default defineNuxtModule({
|
|||||||
|
|
||||||
```ts [runtime/plugin.ejs]
|
```ts [runtime/plugin.ejs]
|
||||||
import { VueFire, useSSRInitialState } from 'vuefire'
|
import { VueFire, useSSRInitialState } from 'vuefire'
|
||||||
import { defineNuxtPlugin } from '#app'
|
import { defineNuxtPlugin } from '#imports'
|
||||||
|
|
||||||
export default defineNuxtPlugin((nuxtApp) => {
|
export default defineNuxtPlugin((nuxtApp) => {
|
||||||
const firebaseApp = nuxtApp.$firebaseApp
|
const firebaseApp = nuxtApp.$firebaseApp
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import type { defineAsyncComponent } from 'vue'
|
import type { defineAsyncComponent } from 'vue'
|
||||||
import { createVNode, defineComponent } from 'vue'
|
import { createVNode, defineComponent } from 'vue'
|
||||||
|
|
||||||
|
import { createError } from '../composables/error'
|
||||||
|
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import * as islandComponents from '#build/components.islands.mjs'
|
import * as islandComponents from '#build/components.islands.mjs'
|
||||||
import { createError } from '#app/composables/error'
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { defineComponent, onErrorCaptured, ref } from 'vue'
|
import { defineComponent, onErrorCaptured, ref } from 'vue'
|
||||||
import { useNuxtApp } from '#app/nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
emits: {
|
emits: {
|
||||||
|
@ -9,9 +9,9 @@ import type { FetchResponse } from 'ofetch'
|
|||||||
|
|
||||||
// eslint-disable-next-line import/no-restricted-paths
|
// eslint-disable-next-line import/no-restricted-paths
|
||||||
import type { NuxtIslandResponse } from '../../core/runtime/nitro/renderer'
|
import type { NuxtIslandResponse } from '../../core/runtime/nitro/renderer'
|
||||||
|
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
||||||
|
import { prerenderRoutes, useRequestEvent } from '../composables/ssr'
|
||||||
import { getFragmentHTML, getSlotProps } from './utils'
|
import { getFragmentHTML, getSlotProps } from './utils'
|
||||||
import { useNuxtApp, useRuntimeConfig } from '#app/nuxt'
|
|
||||||
import { prerenderRoutes, useRequestEvent } from '#app/composables/ssr'
|
|
||||||
|
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { remoteComponentIslands } from '#build/nuxt.config.mjs'
|
import { remoteComponentIslands } from '#build/nuxt.config.mjs'
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
import type { DefineComponent, MaybeRef, VNode } from 'vue'
|
import type { DefineComponent, MaybeRef, VNode } from 'vue'
|
||||||
import { Suspense, Transition, computed, defineComponent, h, inject, mergeProps, nextTick, onMounted, provide, ref, unref } from 'vue'
|
import { Suspense, Transition, computed, defineComponent, h, inject, mergeProps, nextTick, onMounted, provide, ref, unref } from 'vue'
|
||||||
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/no-restricted-paths
|
||||||
|
import type { PageMeta } from '../../pages/runtime/composables'
|
||||||
|
|
||||||
|
import { useRoute } from '../composables/router'
|
||||||
|
import { useNuxtApp } from '../nuxt'
|
||||||
import { _wrapIf } from './utils'
|
import { _wrapIf } from './utils'
|
||||||
import { LayoutMetaSymbol, PageRouteSymbol } from './injections'
|
import { LayoutMetaSymbol, PageRouteSymbol } from './injections'
|
||||||
import type { PageMeta } from '#app'
|
|
||||||
|
|
||||||
import { useRoute } from '#app/composables/router'
|
|
||||||
import { useNuxtApp } from '#app/nuxt'
|
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { useRoute as useVueRouterRoute } from '#build/pages'
|
import { useRoute as useVueRouterRoute } from '#build/pages'
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { computed, defineComponent, h, onBeforeUnmount, ref } from 'vue'
|
import { computed, defineComponent, h, onBeforeUnmount, ref } from 'vue'
|
||||||
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
import { useRouter } from '../composables/router'
|
||||||
import { isChangingPage } from './utils'
|
import { isChangingPage } from './utils'
|
||||||
import { useNuxtApp } from '#app/nuxt'
|
|
||||||
import { useRouter } from '#app/composables/router'
|
|
||||||
|
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { globalMiddleware } from '#build/middleware'
|
import { globalMiddleware } from '#build/middleware'
|
||||||
|
@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { defineAsyncComponent, onErrorCaptured, onServerPrefetch, provide } from 'vue'
|
import { defineAsyncComponent, onErrorCaptured, onServerPrefetch, provide } from 'vue'
|
||||||
import { useNuxtApp } from '#app/nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
import { isNuxtError, showError, useError } from '#app/composables/error'
|
import { isNuxtError, showError, useError } from '../composables/error'
|
||||||
import { useRoute } from '#app/composables/router'
|
import { useRoute } from '../composables/router'
|
||||||
import { PageRouteSymbol } from '#app/components/injections'
|
import { PageRouteSymbol } from '../components/injections'
|
||||||
import AppComponent from '#build/app-component.mjs'
|
import AppComponent from '#build/app-component.mjs'
|
||||||
import ErrorComponent from '#build/error-component.mjs'
|
import ErrorComponent from '#build/error-component.mjs'
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { defineComponent, h, nextTick, onMounted, provide, shallowReactive } from 'vue'
|
import { defineComponent, h, nextTick, onMounted, provide, shallowReactive } from 'vue'
|
||||||
import type { Ref, VNode } from 'vue'
|
import type { Ref, VNode } from 'vue'
|
||||||
import type { RouteLocation, RouteLocationNormalizedLoaded } from '#vue-router'
|
import type { RouteLocation, RouteLocationNormalizedLoaded } from '#vue-router'
|
||||||
import { PageRouteSymbol } from '#app/components/injections'
|
import { PageRouteSymbol } from './injections'
|
||||||
|
|
||||||
export const RouteProvider = defineComponent({
|
export const RouteProvider = defineComponent({
|
||||||
name: 'RouteProvider',
|
name: 'RouteProvider',
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import destr from 'destr'
|
import destr from 'destr'
|
||||||
import { useNuxtApp } from '#app/nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
export interface ReloadNuxtAppOptions {
|
export interface ReloadNuxtAppOptions {
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useNuxtApp } from '../nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
import type { NuxtPayload } from '#app'
|
import type { NuxtPayload } from '../nuxt'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows full control of the hydration cycle to set and receive data from the server.
|
* Allows full control of the hydration cycle to set and receive data from the server.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import type { MatcherExport, RouteMatcher } from 'radix3'
|
import type { MatcherExport, RouteMatcher } from 'radix3'
|
||||||
import { createMatcherFromExport } from 'radix3'
|
import { createMatcherFromExport } from 'radix3'
|
||||||
import { defu } from 'defu'
|
import { defu } from 'defu'
|
||||||
import { useAppConfig } from '#app'
|
import { useAppConfig } from '../config'
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { appManifest as isAppManifestEnabled } from '#build/nuxt.config.mjs'
|
import { appManifest as isAppManifestEnabled } from '#build/nuxt.config.mjs'
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
|
@ -4,8 +4,8 @@ import { useHead } from '@unhead/vue'
|
|||||||
import { getCurrentInstance } from 'vue'
|
import { getCurrentInstance } from 'vue'
|
||||||
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
||||||
|
|
||||||
import { getAppManifest, getRouteRules } from '#app/composables/manifest'
|
import { useRoute } from './router'
|
||||||
import { useRoute } from '#app/composables'
|
import { getAppManifest, getRouteRules } from './manifest'
|
||||||
|
|
||||||
// @ts-expect-error virtual import
|
// @ts-expect-error virtual import
|
||||||
import { appManifest, payloadExtraction, renderJsonPayloads } from '#build/nuxt.config.mjs'
|
import { appManifest, payloadExtraction, renderJsonPayloads } from '#build/nuxt.config.mjs'
|
||||||
|
@ -4,13 +4,14 @@ import type { NavigationFailure, NavigationGuard, RouteLocationNormalized, Route
|
|||||||
import { sanitizeStatusCode } from 'h3'
|
import { sanitizeStatusCode } from 'h3'
|
||||||
import { hasProtocol, isScriptProtocol, joinURL, parseURL, withQuery } from 'ufo'
|
import { hasProtocol, isScriptProtocol, joinURL, parseURL, withQuery } from 'ufo'
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/no-restricted-paths
|
||||||
|
import type { PageMeta } from '../../pages/runtime/composables'
|
||||||
|
|
||||||
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
||||||
|
import { PageRouteSymbol } from '../components/injections'
|
||||||
import type { NuxtError } from './error'
|
import type { NuxtError } from './error'
|
||||||
import { createError, showError } from './error'
|
import { createError, showError } from './error'
|
||||||
|
|
||||||
import type { PageMeta } from '#app'
|
|
||||||
import { PageRouteSymbol } from '#app/components/injections'
|
|
||||||
|
|
||||||
export const useRouter: typeof _useRouter = () => {
|
export const useRouter: typeof _useRouter = () => {
|
||||||
return useNuxtApp()?.$router as Router
|
return useNuxtApp()?.$router as Router
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { getRequestURL } from 'h3'
|
import { getRequestURL } from 'h3'
|
||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
|
import { useRuntimeConfig } from '../nuxt'
|
||||||
import { useRequestEvent } from './ssr'
|
import { useRequestEvent } from './ssr'
|
||||||
import { useRuntimeConfig } from '#app'
|
|
||||||
|
|
||||||
export function useRequestURL () {
|
export function useRequestURL () {
|
||||||
if (import.meta.server) {
|
if (import.meta.server) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import type { CreateOptions } from '#app'
|
import type { CreateOptions } from './nuxt'
|
||||||
|
|
||||||
const entry = import.meta.server
|
const entry = import.meta.server
|
||||||
? (ctx?: CreateOptions['ssrContext']) => import('#app/entry').then(m => m.default(ctx))
|
? (ctx?: CreateOptions['ssrContext']) => import('#app/entry').then(m => m.default(ctx))
|
||||||
|
@ -5,8 +5,8 @@ import { createApp, createSSRApp, nextTick } from 'vue'
|
|||||||
import '#build/paths.mjs'
|
import '#build/paths.mjs'
|
||||||
import '#build/fetch.mjs'
|
import '#build/fetch.mjs'
|
||||||
|
|
||||||
import type { CreateOptions } from '#app'
|
import { applyPlugins, createNuxtApp } from './nuxt'
|
||||||
import { applyPlugins, createNuxtApp } from '#app/nuxt'
|
import type { CreateOptions } from './nuxt'
|
||||||
|
|
||||||
import '#build/css'
|
import '#build/css'
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
/// <reference path="types/augments.d.ts" />
|
/// <reference path="types/augments.d.ts" />
|
||||||
|
|
||||||
export * from './nuxt'
|
export * from './nuxt'
|
||||||
|
// eslint-disable-next-line import/no-restricted-paths
|
||||||
export * from './composables/index'
|
export * from './composables/index'
|
||||||
|
// eslint-disable-next-line import/no-restricted-paths
|
||||||
export * from './components/index'
|
export * from './components/index'
|
||||||
export * from './config'
|
export * from './config'
|
||||||
export * from './compat/idle-callback'
|
export * from './compat/idle-callback'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { defineNuxtRouteMiddleware } from '#app/composables/router'
|
import { defineNuxtRouteMiddleware } from '../composables/router'
|
||||||
import { getRouteRules } from '#app/composables/manifest'
|
import { getRouteRules } from '../composables/manifest'
|
||||||
|
|
||||||
export default defineNuxtRouteMiddleware(async (to) => {
|
export default defineNuxtRouteMiddleware(async (to) => {
|
||||||
if (import.meta.server || import.meta.test) { return }
|
if (import.meta.server || import.meta.test) { return }
|
||||||
|
@ -9,14 +9,14 @@ import type { SSRContext, createRenderer } from 'vue-bundle-renderer/runtime'
|
|||||||
import type { H3Event } from 'h3'
|
import type { H3Event } from 'h3'
|
||||||
import type { AppConfig, AppConfigInput, RuntimeConfig } from 'nuxt/schema'
|
import type { AppConfig, AppConfigInput, RuntimeConfig } from 'nuxt/schema'
|
||||||
import type { RenderResponse } from 'nitropack'
|
import type { RenderResponse } from 'nitropack'
|
||||||
|
|
||||||
import type { MergeHead, VueHeadClient } from '@unhead/vue'
|
import type { MergeHead, VueHeadClient } from '@unhead/vue'
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-restricted-paths
|
// eslint-disable-next-line import/no-restricted-paths
|
||||||
import type { NuxtIslandContext } from '../core/runtime/nitro/renderer'
|
import type { NuxtIslandContext } from '../core/runtime/nitro/renderer'
|
||||||
import type { RouteMiddleware } from '../../app'
|
import type { RouteMiddleware } from '../app/composables/router'
|
||||||
import type { NuxtError } from '../app/composables/error'
|
import type { NuxtError } from '../app/composables/error'
|
||||||
import type { AsyncDataRequestStatus } from '../app/composables/asyncData'
|
import type { AsyncDataRequestStatus } from '../app/composables/asyncData'
|
||||||
import type { NuxtAppManifestMeta } from '#app/composables'
|
import type { NuxtAppManifestMeta } from '../app/composables/manifest'
|
||||||
|
|
||||||
const nuxtAppCtx = /* #__PURE__ */ getContext<NuxtApp>('nuxt-app', {
|
const nuxtAppCtx = /* #__PURE__ */ getContext<NuxtApp>('nuxt-app', {
|
||||||
asyncContext: !!process.env.NUXT_ASYNC_CONTEXT && process.server
|
asyncContext: !!process.env.NUXT_ASYNC_CONTEXT && process.server
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import type { NuxtAppManifestMeta } from '#app'
|
import { defineNuxtPlugin } from '../nuxt'
|
||||||
import { defineNuxtPlugin, getAppManifest, onNuxtReady } from '#app'
|
import { getAppManifest } from '../composables/manifest'
|
||||||
|
import type { NuxtAppManifestMeta } from '../composables/manifest'
|
||||||
|
import { onNuxtReady } from '../composables/ready'
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { buildAssetsURL } from '#build/paths.mjs'
|
import { buildAssetsURL } from '#build/paths.mjs'
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
import type { RouteLocationNormalized } from 'vue-router'
|
import type { RouteLocationNormalized } from 'vue-router'
|
||||||
import { defineNuxtPlugin, useRuntimeConfig } from '#app/nuxt'
|
import { defineNuxtPlugin, useRuntimeConfig } from '../nuxt'
|
||||||
import { useRouter } from '#app/composables/router'
|
import { useRouter } from '../composables/router'
|
||||||
import { reloadNuxtApp } from '#app/composables/chunk'
|
import { reloadNuxtApp } from '../composables/chunk'
|
||||||
|
|
||||||
export default defineNuxtPlugin({
|
export default defineNuxtPlugin({
|
||||||
name: 'nuxt:chunk-reload',
|
name: 'nuxt:chunk-reload',
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { parseURL } from 'ufo'
|
import { parseURL } from 'ufo'
|
||||||
import { useHead } from '@unhead/vue'
|
import { useHead } from '@unhead/vue'
|
||||||
import { defineNuxtPlugin } from '#app/nuxt'
|
import { defineNuxtPlugin } from '../nuxt'
|
||||||
|
|
||||||
export default defineNuxtPlugin({
|
export default defineNuxtPlugin({
|
||||||
name: 'nuxt:cross-origin-prefetch',
|
name: 'nuxt:cross-origin-prefetch',
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { createDebugger } from 'hookable'
|
import { createDebugger } from 'hookable'
|
||||||
import { defineNuxtPlugin } from '#app/nuxt'
|
import { defineNuxtPlugin } from '../nuxt'
|
||||||
|
|
||||||
export default defineNuxtPlugin({
|
export default defineNuxtPlugin({
|
||||||
name: 'nuxt:debug',
|
name: 'nuxt:debug',
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { parseURL } from 'ufo'
|
import { parseURL } from 'ufo'
|
||||||
import { defineNuxtPlugin } from '#app/nuxt'
|
import { defineNuxtPlugin } from '../nuxt'
|
||||||
import { loadPayload } from '#app/composables/payload'
|
import { loadPayload } from '../composables/payload'
|
||||||
import { onNuxtReady } from '#app/composables/ready'
|
import { onNuxtReady } from '../composables/ready'
|
||||||
import { useRouter } from '#app/composables/router'
|
import { useRouter } from '../composables/router'
|
||||||
import { getAppManifest } from '#app/composables/manifest'
|
import { getAppManifest } from '../composables/manifest'
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { appManifest as isAppManifestEnabled } from '#build/nuxt.config.mjs'
|
import { appManifest as isAppManifestEnabled } from '#build/nuxt.config.mjs'
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { defineNuxtPlugin } from '#app/nuxt'
|
import { defineNuxtPlugin } from '../nuxt'
|
||||||
|
|
||||||
export default defineNuxtPlugin({
|
export default defineNuxtPlugin({
|
||||||
name: 'nuxt:webpack-preload',
|
name: 'nuxt:webpack-preload',
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import destr from 'destr'
|
import destr from 'destr'
|
||||||
import { defineNuxtPlugin, useNuxtApp } from '#app/nuxt'
|
import { defineNuxtPlugin, useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
export default defineNuxtPlugin({
|
export default defineNuxtPlugin({
|
||||||
name: 'nuxt:restore-state',
|
name: 'nuxt:restore-state',
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { reactive, ref, shallowReactive, shallowRef } from 'vue'
|
import { reactive, ref, shallowReactive, shallowRef } from 'vue'
|
||||||
import destr from 'destr'
|
import destr from 'destr'
|
||||||
import { definePayloadReviver, getNuxtClientPayload } from '#app/composables/payload'
|
import { definePayloadReviver, getNuxtClientPayload } from '../composables/payload'
|
||||||
import { createError } from '#app/composables/error'
|
import { createError } from '../composables/error'
|
||||||
import { defineNuxtPlugin, useNuxtApp } from '#app/nuxt'
|
import { defineNuxtPlugin, useNuxtApp } from '../nuxt'
|
||||||
|
|
||||||
// @ts-expect-error Virtual file.
|
// @ts-expect-error Virtual file.
|
||||||
import { componentIslands } from '#build/nuxt.config.mjs'
|
import { componentIslands } from '#build/nuxt.config.mjs'
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { isReactive, isRef, isShallow, toRaw } from 'vue'
|
import { isReactive, isRef, isShallow, toRaw } from 'vue'
|
||||||
import { definePayloadReducer } from '#app/composables/payload'
|
import { definePayloadReducer } from '../composables/payload'
|
||||||
import { isNuxtError } from '#app/composables/error'
|
import { isNuxtError } from '../composables/error'
|
||||||
import { defineNuxtPlugin } from '#app/nuxt'
|
import { defineNuxtPlugin } from '../nuxt'
|
||||||
|
|
||||||
// @ts-expect-error Virtual file.
|
// @ts-expect-error Virtual file.
|
||||||
import { componentIslands } from '#build/nuxt.config.mjs'
|
import { componentIslands } from '#build/nuxt.config.mjs'
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { isChangingPage } from '#app/components/utils'
|
import { isChangingPage } from '../components/utils'
|
||||||
import { useRouter } from '#app/composables/router'
|
import { useRouter } from '../composables/router'
|
||||||
import { defineNuxtPlugin } from '#app/nuxt'
|
import { defineNuxtPlugin } from '../nuxt'
|
||||||
|
|
||||||
export default defineNuxtPlugin((nuxtApp) => {
|
export default defineNuxtPlugin((nuxtApp) => {
|
||||||
if (!document.startViewTransition) { return }
|
if (!document.startViewTransition) { return }
|
||||||
|
@ -285,7 +285,7 @@ export const appConfigTemplate: NuxtTemplate = {
|
|||||||
write: true,
|
write: true,
|
||||||
getContents: async ({ app, nuxt }) => {
|
getContents: async ({ app, nuxt }) => {
|
||||||
return `
|
return `
|
||||||
import { updateAppConfig } from '#app'
|
import { updateAppConfig } from '#app/config'
|
||||||
import { defuFn } from '${await _resolveId('defu')}'
|
import { defuFn } from '${await _resolveId('defu')}'
|
||||||
|
|
||||||
const inlineConfig = ${JSON.stringify(nuxt.options.appConfig, null, 2)}
|
const inlineConfig = ${JSON.stringify(nuxt.options.appConfig, null, 2)}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { createHead as createClientHead, setHeadInjectionHandler } from '@unhead/vue'
|
import { createHead as createClientHead, setHeadInjectionHandler } from '@unhead/vue'
|
||||||
import { renderDOMHead } from '@unhead/dom'
|
import { renderDOMHead } from '@unhead/dom'
|
||||||
import { defineNuxtPlugin } from '#app/nuxt'
|
import { defineNuxtPlugin, useNuxtApp } from '#app/nuxt'
|
||||||
import { useNuxtApp } from '#app'
|
|
||||||
|
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import unheadPlugins from '#build/unhead-plugins.mjs'
|
import unheadPlugins from '#build/unhead-plugins.mjs'
|
||||||
|
@ -12,70 +12,89 @@ const commonPresets: InlinePreset[] = [
|
|||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|
||||||
const appPreset = defineUnimportPreset({
|
const granularAppPresets: InlinePreset[] = [
|
||||||
from: '#app',
|
{
|
||||||
imports: [
|
from: '#app/components/nuxt-link',
|
||||||
'useAsyncData',
|
imports: ['defineNuxtLink']
|
||||||
'useLazyAsyncData',
|
},
|
||||||
'useNuxtData',
|
{
|
||||||
'refreshNuxtData',
|
imports: ['useNuxtApp', 'defineNuxtPlugin', 'definePayloadPlugin', 'useRuntimeConfig', 'defineAppConfig'],
|
||||||
'clearNuxtData',
|
from: '#app/nuxt'
|
||||||
'defineNuxtComponent',
|
},
|
||||||
'useNuxtApp',
|
{
|
||||||
'defineNuxtPlugin',
|
imports: ['requestIdleCallback', 'cancelIdleCallback'],
|
||||||
'definePayloadPlugin',
|
from: '#app/compat/idle-callback'
|
||||||
'reloadNuxtApp',
|
},
|
||||||
'useRuntimeConfig',
|
{
|
||||||
'useState',
|
imports: ['useAppConfig', 'updateAppConfig'],
|
||||||
'clearNuxtState',
|
from: '#app/config'
|
||||||
'useFetch',
|
},
|
||||||
'useLazyFetch',
|
{
|
||||||
'useCookie',
|
imports: ['defineNuxtComponent'],
|
||||||
'useRequestHeaders',
|
from: '#app/composables/component'
|
||||||
'useRequestEvent',
|
},
|
||||||
'useRequestFetch',
|
{
|
||||||
'useRequestURL',
|
imports: ['useAsyncData', 'useLazyAsyncData', 'useNuxtData', 'refreshNuxtData', 'clearNuxtData'],
|
||||||
'setResponseStatus',
|
from: '#app/composables/asyncData'
|
||||||
'setPageLayout',
|
},
|
||||||
'prerenderRoutes',
|
{
|
||||||
'onNuxtReady',
|
imports: ['useHydration'],
|
||||||
'useRouter',
|
from: '#app/composables/hydrate'
|
||||||
'useRoute',
|
},
|
||||||
'defineNuxtRouteMiddleware',
|
{
|
||||||
'navigateTo',
|
imports: ['useState', 'clearNuxtState'],
|
||||||
'abortNavigation',
|
from: '#app/composables/state'
|
||||||
'addRouteMiddleware',
|
},
|
||||||
'showError',
|
{
|
||||||
'clearError',
|
imports: ['clearError', 'createError', 'isNuxtError', 'showError', 'useError'],
|
||||||
'isNuxtError',
|
from: '#app/composables/error'
|
||||||
'useError',
|
},
|
||||||
'createError',
|
{
|
||||||
'defineNuxtLink',
|
imports: ['useFetch', 'useLazyFetch'],
|
||||||
'useAppConfig',
|
from: '#app/composables/fetch'
|
||||||
'updateAppConfig',
|
},
|
||||||
'defineAppConfig',
|
{
|
||||||
'preloadComponents',
|
imports: ['useCookie'],
|
||||||
'preloadRouteComponents',
|
from: '#app/composables/cookie'
|
||||||
'prefetchComponents',
|
},
|
||||||
'loadPayload',
|
{
|
||||||
'preloadPayload',
|
imports: ['prerenderRoutes', 'useRequestHeaders', 'useRequestEvent', 'useRequestFetch', 'setResponseStatus'],
|
||||||
'isPrerendered',
|
from: '#app/composables/ssr'
|
||||||
'getAppManifest',
|
},
|
||||||
'getRouteRules',
|
{
|
||||||
'definePayloadReducer',
|
imports: ['onNuxtReady'],
|
||||||
'definePayloadReviver',
|
from: '#app/composables/ready'
|
||||||
'requestIdleCallback',
|
},
|
||||||
'cancelIdleCallback'
|
{
|
||||||
]
|
imports: ['preloadComponents', 'prefetchComponents', 'preloadRouteComponents'],
|
||||||
})
|
from: '#app/composables/preload'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
imports: ['abortNavigation', 'addRouteMiddleware', 'defineNuxtRouteMiddleware', 'setPageLayout', 'navigateTo', 'useRoute', 'useRouter'],
|
||||||
|
from: '#app/composables/router'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
imports: ['isPrerendered', 'loadPayload', 'preloadPayload', 'definePayloadReducer', 'definePayloadReviver'],
|
||||||
|
from: '#app/composables/payload'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
imports: ['getAppManifest', 'getRouteRules'],
|
||||||
|
from: '#app/composables/manifest'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
imports: ['reloadNuxtApp'],
|
||||||
|
from: '#app/composables/chunk'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
imports: ['useRequestURL'],
|
||||||
|
from: '#app/composables/url'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
// vue-router
|
// This is a separate preset as we'll swap these out for import from `vue-router` itself in `pages` module
|
||||||
const routerPreset = defineUnimportPreset({
|
const routerPreset = defineUnimportPreset({
|
||||||
from: '#app',
|
imports: ['onBeforeRouteLeave', 'onBeforeRouteUpdate'],
|
||||||
imports: [
|
from: '#app/composables/router'
|
||||||
'onBeforeRouteLeave',
|
|
||||||
'onBeforeRouteUpdate'
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// vue
|
// vue
|
||||||
@ -180,7 +199,7 @@ const vueTypesPreset = defineUnimportPreset({
|
|||||||
|
|
||||||
export const defaultPresets: InlinePreset[] = [
|
export const defaultPresets: InlinePreset[] = [
|
||||||
...commonPresets,
|
...commonPresets,
|
||||||
appPreset,
|
...granularAppPresets,
|
||||||
routerPreset,
|
routerPreset,
|
||||||
vuePreset,
|
vuePreset,
|
||||||
vueTypesPreset
|
vueTypesPreset
|
||||||
|
@ -182,7 +182,7 @@ export default defineNuxtModule({
|
|||||||
|
|
||||||
// Add vue-router route guard imports
|
// Add vue-router route guard imports
|
||||||
nuxt.hook('imports:sources', (sources) => {
|
nuxt.hook('imports:sources', (sources) => {
|
||||||
const routerImports = sources.find(s => s.from === '#app' && s.imports.includes('onBeforeRouteLeave'))
|
const routerImports = sources.find(s => s.from === '#app/composables/router' && s.imports.includes('onBeforeRouteLeave'))
|
||||||
if (routerImports) {
|
if (routerImports) {
|
||||||
routerImports.from = '#vue-router'
|
routerImports.from = '#vue-router'
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { getCurrentInstance } from 'vue'
|
|||||||
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteRecordRedirectOption } from '#vue-router'
|
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteRecordRedirectOption } from '#vue-router'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import type { NitroRouteConfig } from 'nitropack'
|
import type { NitroRouteConfig } from 'nitropack'
|
||||||
import type { NuxtError } from '#app'
|
import type { NuxtError } from '#app/composables/error'
|
||||||
|
|
||||||
export interface PageMeta {
|
export interface PageMeta {
|
||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
|
@ -11,7 +11,10 @@ import {
|
|||||||
import { createError } from 'h3'
|
import { createError } from 'h3'
|
||||||
import { isEqual, withoutBase } from 'ufo'
|
import { isEqual, withoutBase } from 'ufo'
|
||||||
|
|
||||||
import type { PageMeta, Plugin, RouteMiddleware } from '../../../app/index'
|
import type { PageMeta } from '../composables'
|
||||||
|
|
||||||
|
import type { RouteMiddleware } from '#app/composables/router'
|
||||||
|
import type { Plugin } from '#app/nuxt'
|
||||||
import { defineNuxtPlugin, useRuntimeConfig } from '#app/nuxt'
|
import { defineNuxtPlugin, useRuntimeConfig } from '#app/nuxt'
|
||||||
import { clearError, showError, useError } from '#app/composables/error'
|
import { clearError, showError, useError } from '#app/composables/error'
|
||||||
import { navigateTo } from '#app/composables/router'
|
import { navigateTo } from '#app/composables/router'
|
||||||
|
@ -68,7 +68,7 @@ describe('imports:nuxt', () => {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
it(`should register ${name} globally`, () => {
|
it(`should register ${name} globally`, () => {
|
||||||
expect(defaultPresets.flatMap(a => a.from === '#app' ? a.imports : [])).to.include(name)
|
expect(defaultPresets.flatMap(a => a.from.startsWith('#app/') ? a.imports : [])).to.include(name)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user