This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
hooks.ts
123 lines (98 loc) · 4.28 KB
/
hooks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import type { TSConfig } from 'pkg-types'
import type { Server as HttpServer } from 'node:http'
import type { Server as HttpsServer } from 'node:https'
import type { InlineConfig as ViteInlineConfig, ViteDevServer } from 'vite'
import type { Manifest } from 'vue-bundle-renderer'
import type { EventHandler } from 'h3'
import type { Import, InlinePreset } from 'unimport'
import type { Compiler, Configuration, Stats } from 'webpack'
import type { Nuxt, NuxtApp, ResolvedNuxtTemplate } from './nuxt'
import type { Nitro, NitroConfig } from 'nitropack'
import type { Component, ComponentsOptions } from './components'
import { NuxtCompatibility, NuxtCompatibilityIssues } from '..'
export type HookResult = Promise<void> | void
// https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html
export type TSReference = { types: string } | { path: string }
export type WatchEvent = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir'
export type NuxtPage = {
name?: string
path: string
file: string
meta?: Record<string, any>
alias?: string[] | string
redirect?: string
children?: NuxtPage[]
}
export type NuxtMiddleware = {
name: string
path: string
global?: boolean
}
export type NuxtLayout = {
name: string
file: string
}
export interface ImportPresetWithDeprecation extends InlinePreset {
/**
* @deprecated renamed to `imports`
*/
names?: string[]
}
export interface GenerateAppOptions {
filter?: (template: ResolvedNuxtTemplate<any>) => boolean
}
export interface NuxtHooks {
// Kit
'kit:compatibility': (compatibility: NuxtCompatibility, issues: NuxtCompatibilityIssues) => HookResult
// Nuxt
'ready': (nuxt: Nuxt) => HookResult
'close': (nuxt: Nuxt) => HookResult
'modules:before': () => HookResult
'modules:done': () => HookResult
'app:resolve': (app: NuxtApp) => HookResult
'app:templates': (app: NuxtApp) => HookResult
'app:templatesGenerated': (app: NuxtApp) => HookResult
'build:before': () => HookResult
'build:done': () => HookResult
'build:manifest': (manifest: Manifest) => HookResult
'builder:generateApp': (options?: GenerateAppOptions) => HookResult
'builder:watch': (event: WatchEvent, path: string) => HookResult
'pages:extend': (pages: NuxtPage[]) => HookResult
'server:devHandler': (handler: EventHandler) => HookResult
// Auto imports
/** @deprecated Please use `imports:sources` hook */
'autoImports:sources': (presets: ImportPresetWithDeprecation[]) => HookResult
/** @deprecated Please use `imports:extend` hook */
'autoImports:extend': (imports: Import[]) => HookResult
/** @deprecated Please use `imports:dirs` hook */
'autoImports:dirs': (dirs: string[]) => HookResult
'imports:sources': (presets: ImportPresetWithDeprecation[]) => HookResult
'imports:extend': (imports: Import[]) => HookResult
'imports:dirs': (dirs: string[]) => HookResult
// Components
'components:dirs': (dirs: ComponentsOptions['dirs']) => HookResult
'components:extend': (components: Component[]) => HookResult
// Nitropack
'nitro:config': (nitroConfig: NitroConfig) => HookResult
'nitro:init': (nitro: Nitro) => HookResult
'nitro:build:before': (nitro: Nitro) => HookResult
'prerender:routes': (ctx: { routes: Set<string> }) => HookResult
// Nuxi
'build:error': (error: Error) => HookResult
'prepare:types': (options: { references: TSReference[], declarations: string[], tsConfig: TSConfig }) => HookResult
'listen': (listenerServer: HttpServer | HttpsServer, listener: any) => HookResult
// Vite
'vite:extend': (viteBuildContext: { nuxt: Nuxt, config: ViteInlineConfig }) => HookResult
'vite:extendConfig': (viteInlineConfig: ViteInlineConfig, env: { isClient: boolean, isServer: boolean }) => HookResult
'vite:serverCreated': (viteServer: ViteDevServer, env: { isClient: boolean, isServer: boolean }) => HookResult
'vite:compiled': () => HookResult
// Webpack
'webpack:config': (webpackConfigs: Configuration[]) => HookResult
'webpack:compile': (options: { name: string, compiler: Compiler }) => HookResult
'webpack:compiled': (options: { name: string, compiler: Compiler, stats: Stats }) => HookResult
'webpack:change': (shortPath: string) => void
'webpack:error': () => void
'webpack:done': () => void
'webpack:progress': (statesArray: any[]) => void
}
export type NuxtHookName = keyof NuxtHooks