@hazejs/vite 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +30 -2
- package/client.d.ts +13 -0
- package/dist/index.d.mts +373 -0
- package/dist/index.mjs +1685 -0
- package/package.json +67 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present hazejs contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hazejs/vite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Vite plugin for hazejs: hot-reloading backend, full-stack dev server, deployment presets and preview.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @hazejs/vite
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// vite.config.ts
|
|
15
|
+
import { haze } from '@hazejs/vite'
|
|
16
|
+
import { defineConfig } from 'vite'
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
plugins: [
|
|
20
|
+
haze()
|
|
21
|
+
]
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
In dev, requests to your backend routes are served by the app in `server/` (configurable in `haze.config.ts`); `vite build` emits `dist/client` + `dist/server`; `vite preview` runs the real build output for the selected preset.
|
|
26
|
+
|
|
27
|
+
Part of [hazejs](https://github.com/penna-org/haze) — see the main README for documentation.
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
[MIT](./LICENSE)
|
package/client.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// 虚拟模块类型声明:在 tsconfig 的 types 中加入 "@hazejs/vite/client"
|
|
2
|
+
|
|
3
|
+
declare module 'virtual:haze/app' {
|
|
4
|
+
import type { Application, ApplicationOptions } from '@hazejs/core'
|
|
5
|
+
|
|
6
|
+
/** 使用编译期发现的 config / route / provider / exception 创建应用 */
|
|
7
|
+
export function createApp(options?: ApplicationOptions): Promise<Application>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare module 'virtual:haze/migrations' {
|
|
11
|
+
/** 打包进产物的迁移文件(相对后端源码目录的路径 → 内容),用于 runMigrations({ files }) */
|
|
12
|
+
export const files: Record<string, string>
|
|
13
|
+
}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { Plugin, PreviewServer, UserConfig, ViteDevServer } from "vite";
|
|
2
|
+
import { Application, RouteInfo } from "@hazejs/core";
|
|
3
|
+
/** 依赖处理选项(haze.config.ts 的 externals) */
|
|
4
|
+
interface ExternalsOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 构建后把仍为 external 的依赖按实际引用的文件追踪复制到产物的 node_modules(node / bun / deno),默认 true。
|
|
7
|
+
* false 时 node / bun 不打包依赖,运行时从项目的 node_modules 加载。aws-lambda / vercel 始终追踪。
|
|
8
|
+
*/
|
|
9
|
+
trace?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 保持 external 并追踪进产物的包(默认已包含数据库驱动与已知的原生 / 无法打包的包)。
|
|
12
|
+
* `pkg*` 表示整包复制(运行时动态读取文件、静态分析不到时)。
|
|
13
|
+
*/
|
|
14
|
+
traceDeps?: string[];
|
|
15
|
+
/** 强制打包进产物的包(覆盖默认的 external 列表) */
|
|
16
|
+
inline?: string[];
|
|
17
|
+
}
|
|
18
|
+
interface TraceResult {
|
|
19
|
+
/** 复制进产物的包(含传递依赖) */
|
|
20
|
+
packages: string[];
|
|
21
|
+
/** 构建机与目标平台不一致的原生包 */
|
|
22
|
+
foreignNative: string[];
|
|
23
|
+
}
|
|
24
|
+
export declare const PRESET_NAMES: readonly ["node", "bun", "deno", "docker", "cloudflare", "vercel", "netlify", "aws-lambda"];
|
|
25
|
+
type PresetName = (typeof PRESET_NAMES)[number];
|
|
26
|
+
/** haze.config.ts 的 cloudflare 选项 */
|
|
27
|
+
interface CloudflareOptions {
|
|
28
|
+
/**
|
|
29
|
+
* 合并进生成的 wrangler.json(D1 / KV / R2 绑定、vars、routes 等)。
|
|
30
|
+
* `d1_databases` 中未设置 `migrations_dir` 的数据库使用产物中的 `migrations`(默认连接的迁移)。
|
|
31
|
+
*/
|
|
32
|
+
wrangler?: Record<string, unknown>;
|
|
33
|
+
/** 生成 WebSocket 的 Durable Object(默认在路由中发现 r.ws() 时生成) */
|
|
34
|
+
websocket?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** haze.config.ts 的 vercel 选项 */
|
|
37
|
+
interface VercelOptions {
|
|
38
|
+
/** 定时任务的触发频率(Vercel Cron 表达式),默认每分钟;Hobby 计划只允许每天一次 */
|
|
39
|
+
cron?: string;
|
|
40
|
+
}
|
|
41
|
+
interface PresetContext {
|
|
42
|
+
root: string;
|
|
43
|
+
/** haze.config.ts 的 externals 选项 */
|
|
44
|
+
externalsOptions: ExternalsOptions;
|
|
45
|
+
/** 后端源码目录(绝对路径) */
|
|
46
|
+
srcDir: string;
|
|
47
|
+
/** haze.config.ts 的 outDir(绝对路径) */
|
|
48
|
+
outDir: string;
|
|
49
|
+
/** 是否包含前端(Vue 等)构建 */
|
|
50
|
+
fullstack: boolean;
|
|
51
|
+
/** 交给后端处理的路径前缀(全栈模式) */
|
|
52
|
+
prefixes: string[];
|
|
53
|
+
port: number;
|
|
54
|
+
host: string | undefined;
|
|
55
|
+
/** 项目使用 @hazejs/orm:生成生产迁移入口 */
|
|
56
|
+
orm: boolean;
|
|
57
|
+
cloudflare: CloudflareOptions | undefined;
|
|
58
|
+
vercel: VercelOptions | undefined;
|
|
59
|
+
/** 存在 schedule/*.ts:生成 Cron Triggers / Vercel Cron 等触发配置 */
|
|
60
|
+
schedules: boolean;
|
|
61
|
+
/** 路由中使用了 r.ws():Cloudflare 生成 WebSocket 的 Durable Object */
|
|
62
|
+
websocket: boolean;
|
|
63
|
+
}
|
|
64
|
+
interface Layout {
|
|
65
|
+
/** 服务端产物目录 */
|
|
66
|
+
serverDir: string;
|
|
67
|
+
/** 前端产物目录(全栈模式) */
|
|
68
|
+
clientDir: string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* 运行时托管前端产物的目录(相对服务端入口);
|
|
71
|
+
* undefined 表示静态资源由平台(CDN)提供
|
|
72
|
+
*/
|
|
73
|
+
staticFromServer: string | undefined;
|
|
74
|
+
}
|
|
75
|
+
interface FinalizeContext extends PresetContext {
|
|
76
|
+
layout: Layout;
|
|
77
|
+
/** 服务端产物中仍需从 node_modules 加载的依赖 */
|
|
78
|
+
externals: string[];
|
|
79
|
+
/** 追踪复制进产物的依赖(未追踪时为 undefined) */
|
|
80
|
+
traced: TraceResult | undefined;
|
|
81
|
+
}
|
|
82
|
+
interface Preset {
|
|
83
|
+
name: PresetName;
|
|
84
|
+
/**
|
|
85
|
+
* - external:依赖保留在 node_modules
|
|
86
|
+
* - drivers-external:除数据库驱动(原生二进制 / WASM)外全部打包,驱动运行时安装或随产物复制
|
|
87
|
+
* - all:全部打包(Edge 运行时没有 node_modules,驱动按 workerd 等条件使用其 Web 版本)
|
|
88
|
+
*/
|
|
89
|
+
bundle: 'external' | 'drivers-external' | 'all';
|
|
90
|
+
/**
|
|
91
|
+
* 构建后把 external 依赖追踪复制进 `<serverDir>/node_modules`:
|
|
92
|
+
* - default:默认开启,`externals.trace: false` 时关闭(node / bun 改为依赖全部 external)
|
|
93
|
+
* - always:产物必须自带依赖(Serverless 函数)
|
|
94
|
+
*/
|
|
95
|
+
trace?: 'default' | 'always';
|
|
96
|
+
/** 产物的运行平台(与构建机不同时检查追踪到的原生包) */
|
|
97
|
+
runtimePlatform?: NodeJS.Platform;
|
|
98
|
+
/** 构建时的 package.json exports 条件 */
|
|
99
|
+
conditions?: string[];
|
|
100
|
+
target?: string;
|
|
101
|
+
/** 打包平台:Edge 运行时使用 browser,避免生成依赖 import.meta.url 的 createRequire 辅助代码 */
|
|
102
|
+
platform?: 'node' | 'browser' | 'neutral';
|
|
103
|
+
/** 解析 package.json 的入口字段(含 browser 时同时应用 browser 字段的文件映射) */
|
|
104
|
+
mainFields?: string[];
|
|
105
|
+
/** 替换为“调用即报错”空模块的包(该运行时不支持) */
|
|
106
|
+
unsupported?: string[];
|
|
107
|
+
/** 输出单文件(Workers 要求入口模块只导出处理器,不能被拆分出的 chunk 反向导入) */
|
|
108
|
+
singleFile?: boolean;
|
|
109
|
+
/** 保留为运行时导入的模块(如 Workers 的 `cloudflare:*`) */
|
|
110
|
+
external?: RegExp[];
|
|
111
|
+
/** 输出独立的迁移脚本 `migrate.mjs`(常驻进程型运行时,部署前执行) */
|
|
112
|
+
migrateScript?: boolean;
|
|
113
|
+
layout: (context: PresetContext) => Layout;
|
|
114
|
+
/** 生产入口(virtual:haze/server-entry)源码 */
|
|
115
|
+
entry: (context: PresetContext & {
|
|
116
|
+
layout: Layout;
|
|
117
|
+
}) => string;
|
|
118
|
+
/** 构建完成后生成平台配置、复制依赖等 */
|
|
119
|
+
finalize?: (context: FinalizeContext) => Promise<void>;
|
|
120
|
+
/** 构建完成后提示如何运行 / 部署 */
|
|
121
|
+
hint: (context: FinalizeContext) => string;
|
|
122
|
+
}
|
|
123
|
+
export declare const presets: Record<PresetName, Preset>;
|
|
124
|
+
export declare function resolvePreset(name: string | undefined): Preset;
|
|
125
|
+
interface HazePluginOptions {
|
|
126
|
+
/** 后端源码目录,相对 Vite root 或绝对路径;默认读取 haze.config.ts,否则为 `.` */
|
|
127
|
+
srcDir?: string;
|
|
128
|
+
/** 交给后端处理的路径前缀(全栈模式),默认 `/api` */
|
|
129
|
+
prefix?: string | string[];
|
|
130
|
+
/** 指向 srcDir 的路径别名,默认 `~`;设为 false 关闭 */
|
|
131
|
+
alias?: string | false;
|
|
132
|
+
/** 生产入口的默认端口 / 地址(运行时 PORT / HOST 环境变量优先) */
|
|
133
|
+
port?: number;
|
|
134
|
+
host?: string;
|
|
135
|
+
/** 开发时自动生成类型(默认读取 haze.config.ts,否则为 true) */
|
|
136
|
+
typegen?: boolean;
|
|
137
|
+
/** 部署预设,默认读取 HAZE_PRESET 环境变量 / haze.config.ts,否则为 node */
|
|
138
|
+
preset?: PresetName;
|
|
139
|
+
/** 产物目录(默认读取 haze.config.ts) */
|
|
140
|
+
outDir?: string;
|
|
141
|
+
/** cloudflare 预设的 wrangler 配置(默认读取 haze.config.ts) */
|
|
142
|
+
cloudflare?: CloudflareOptions;
|
|
143
|
+
/** vercel 预设的选项(默认读取 haze.config.ts) */
|
|
144
|
+
vercel?: VercelOptions;
|
|
145
|
+
/** 依赖的打包 / 追踪方式(默认读取 haze.config.ts) */
|
|
146
|
+
externals?: ExternalsOptions;
|
|
147
|
+
/**
|
|
148
|
+
* 不集成 Vite 开发服务器与前端构建(不挂载中间件、不配置 client / ssr 构建)。
|
|
149
|
+
* 由 `haze dev / build` 与 `@hazejs/testing` 使用。
|
|
150
|
+
*/
|
|
151
|
+
standalone?: boolean;
|
|
152
|
+
}
|
|
153
|
+
interface ReloadEvent {
|
|
154
|
+
type: 'create' | 'update' | 'delete';
|
|
155
|
+
file: string;
|
|
156
|
+
}
|
|
157
|
+
interface HazePluginApi {
|
|
158
|
+
/** 后端相关文件变化时通知(开发服务器据此热替换应用) */
|
|
159
|
+
onReload: (listener: (event: ReloadEvent) => void) => () => void;
|
|
160
|
+
/** 解析后的目录与选项(config 钩子执行之后可用) */
|
|
161
|
+
settings: () => Readonly<Pick<Settings, 'root' | 'srcDir' | 'typegen' | 'preset'>>;
|
|
162
|
+
/** 最近一次构建的结果(buildApp 完成后可用) */
|
|
163
|
+
lastBuild: () => BuildInfo | undefined;
|
|
164
|
+
}
|
|
165
|
+
interface BuildInfo {
|
|
166
|
+
preset: PresetName;
|
|
167
|
+
layout: Layout;
|
|
168
|
+
/** 运行时仍需从 node_modules 加载的依赖 */
|
|
169
|
+
externals: string[];
|
|
170
|
+
/** 追踪复制进产物 node_modules 的依赖 */
|
|
171
|
+
traced: TraceResult | undefined;
|
|
172
|
+
/** 服务端入口 */
|
|
173
|
+
entry: string;
|
|
174
|
+
/** 生产迁移脚本(使用 @hazejs/orm 且为常驻进程型预设时) */
|
|
175
|
+
migrate?: string;
|
|
176
|
+
/** 运行 / 部署提示 */
|
|
177
|
+
hint: string;
|
|
178
|
+
}
|
|
179
|
+
interface Settings {
|
|
180
|
+
root: string;
|
|
181
|
+
srcDir: string;
|
|
182
|
+
outDir: string;
|
|
183
|
+
typegen: boolean;
|
|
184
|
+
port: number;
|
|
185
|
+
host: string | undefined;
|
|
186
|
+
prefixes: string[];
|
|
187
|
+
fullstack: boolean;
|
|
188
|
+
preset: string;
|
|
189
|
+
orm: boolean;
|
|
190
|
+
cloudflare: CloudflareOptions | undefined;
|
|
191
|
+
vercel: VercelOptions | undefined;
|
|
192
|
+
externals: ExternalsOptions;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* hazejs 的 Vite 插件。
|
|
196
|
+
*
|
|
197
|
+
* - 纯后端项目:由 `hazejs` 命令行内部使用
|
|
198
|
+
* - Vue 等前端项目:在 vite.config.ts 中加入 `haze()`,开发时把 `/api/**` 交给后端(同端口、热替换),
|
|
199
|
+
* `vite build` 一次产出 `dist/client` 与 `dist/server`
|
|
200
|
+
*/
|
|
201
|
+
export declare function haze(options?: HazePluginOptions): Plugin<HazePluginApi>;
|
|
202
|
+
interface BuildServerOptions {
|
|
203
|
+
root?: string;
|
|
204
|
+
/** 覆盖 haze.config.ts 中的 outDir */
|
|
205
|
+
outDir?: string;
|
|
206
|
+
/** 部署预设,默认读取 haze.config.ts,否则为 node */
|
|
207
|
+
preset?: PresetName;
|
|
208
|
+
minify?: boolean;
|
|
209
|
+
sourcemap?: boolean;
|
|
210
|
+
}
|
|
211
|
+
interface BuildServerResult extends BuildInfo {
|
|
212
|
+
outDir: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 构建纯后端项目的生产产物。产物布局、打包策略与入口由部署预设决定;
|
|
216
|
+
* node 预设下依赖保持 external(运行时需要 node_modules),`.env` 从运行时工作目录加载。
|
|
217
|
+
*/
|
|
218
|
+
export declare function buildServer(options?: BuildServerOptions): Promise<BuildServerResult>;
|
|
219
|
+
interface HazeConfig {
|
|
220
|
+
/** 后端源码目录(相对项目根),默认 `.`;全栈项目一般为 `server` */
|
|
221
|
+
srcDir?: string;
|
|
222
|
+
/** 开发服务器端口,默认 3000(环境变量 PORT 优先) */
|
|
223
|
+
port?: number;
|
|
224
|
+
/** 监听地址,默认 localhost */
|
|
225
|
+
host?: string;
|
|
226
|
+
/** 构建输出目录,默认 `dist` */
|
|
227
|
+
outDir?: string;
|
|
228
|
+
/** 开发时自动生成配置键 / 路由名类型到 .haze/types,默认 true */
|
|
229
|
+
typegen?: boolean;
|
|
230
|
+
/** 部署预设:node(默认)| bun | deno | docker | cloudflare | vercel | netlify | aws-lambda */
|
|
231
|
+
preset?: PresetName;
|
|
232
|
+
/** cloudflare 预设:合并进 wrangler.json 的绑定等配置 */
|
|
233
|
+
cloudflare?: CloudflareOptions;
|
|
234
|
+
/** vercel 预设:定时任务触发频率等 */
|
|
235
|
+
vercel?: VercelOptions;
|
|
236
|
+
/** 依赖处理:默认能打包的都打包,驱动 / 原生模块追踪复制进产物的 node_modules */
|
|
237
|
+
externals?: ExternalsOptions;
|
|
238
|
+
/** 透传给 Vite 的配置(插件、别名等) */
|
|
239
|
+
vite?: UserConfig;
|
|
240
|
+
}
|
|
241
|
+
interface ResolvedHazeConfig {
|
|
242
|
+
root: string;
|
|
243
|
+
srcDir: string;
|
|
244
|
+
port: number;
|
|
245
|
+
host: string | undefined;
|
|
246
|
+
outDir: string;
|
|
247
|
+
typegen: boolean;
|
|
248
|
+
preset: PresetName | undefined;
|
|
249
|
+
cloudflare: CloudflareOptions | undefined;
|
|
250
|
+
vercel: VercelOptions | undefined;
|
|
251
|
+
externals: ExternalsOptions | undefined;
|
|
252
|
+
vite: UserConfig;
|
|
253
|
+
configFile: string | undefined;
|
|
254
|
+
}
|
|
255
|
+
export declare function defineHazeConfig(config: HazeConfig): HazeConfig;
|
|
256
|
+
/** 存在 vite.config.* 视为全栈项目:由用户的 Vite 配置(含 haze() 插件)驱动 */
|
|
257
|
+
export declare function findViteConfig(root: string): string | undefined;
|
|
258
|
+
/** 读取项目根目录下的 `haze.config.ts`(可选) */
|
|
259
|
+
export declare function loadHazeConfig(root: string, mode?: string): Promise<ResolvedHazeConfig>;
|
|
260
|
+
export declare const CONFIG_BASENAME = "haze.config";
|
|
261
|
+
export declare const VIRTUAL_MODULES: {
|
|
262
|
+
/** 编译期发现的配置 / 路由 / 提供者 / 异常处理器 */
|
|
263
|
+
readonly manifest: "virtual:haze/manifest";
|
|
264
|
+
/** `createApp(options)`:用 manifest 创建应用 */
|
|
265
|
+
readonly app: "virtual:haze/app";
|
|
266
|
+
/** 生产环境入口:创建应用并监听端口 */
|
|
267
|
+
readonly serverEntry: "virtual:haze/server-entry";
|
|
268
|
+
/** 打包进产物的迁移文件(database/ 下的 drizzle-kit 输出) */
|
|
269
|
+
readonly migrations: "virtual:haze/migrations";
|
|
270
|
+
/** 生产迁移脚本入口(migrate.mjs) */
|
|
271
|
+
readonly migrateEntry: "virtual:haze/migrate-entry";
|
|
272
|
+
/** 队列 worker 与定时任务入口(worker.mjs) */
|
|
273
|
+
readonly workerEntry: "virtual:haze/worker-entry";
|
|
274
|
+
};
|
|
275
|
+
interface ReloadResult {
|
|
276
|
+
ok: boolean;
|
|
277
|
+
/** 触发重载的文件(相对项目根),首次启动为 undefined */
|
|
278
|
+
file?: string;
|
|
279
|
+
duration: number;
|
|
280
|
+
error?: unknown;
|
|
281
|
+
}
|
|
282
|
+
interface AppHostOptions {
|
|
283
|
+
vite: ViteDevServer;
|
|
284
|
+
api: HazePluginApi;
|
|
285
|
+
/** 文件变化后的防抖时间,默认 30ms */
|
|
286
|
+
debounce?: number;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* 托管开发态应用:通过 Vite ModuleRunner 执行应用代码,文件变化时重新执行并原子替换。
|
|
290
|
+
* 独立开发服务器(srvx)与 Vue 项目中的 Vite 中间件共用它。
|
|
291
|
+
*/
|
|
292
|
+
interface AppHost {
|
|
293
|
+
/** 当前正在服务的应用 */
|
|
294
|
+
readonly app: Application | undefined;
|
|
295
|
+
/** 首次加载应用(幂等);未调用时首个请求会自动触发 */
|
|
296
|
+
start: () => Promise<ReloadResult>;
|
|
297
|
+
fetch: (request: Request) => Promise<Response>;
|
|
298
|
+
/** 手动触发一次重载 */
|
|
299
|
+
reload: (file?: string) => Promise<ReloadResult>;
|
|
300
|
+
onReload: (listener: (result: ReloadResult) => void) => () => void;
|
|
301
|
+
/** 在应用的模块图中执行模块(与应用共享同一份依赖实例,例如数据库连接) */
|
|
302
|
+
import: <T = any>(id: string) => Promise<T>;
|
|
303
|
+
close: () => Promise<void>;
|
|
304
|
+
}
|
|
305
|
+
export declare function createAppHost({ vite, api, debounce }: AppHostOptions): AppHost;
|
|
306
|
+
interface DevServerOptions {
|
|
307
|
+
/** 项目根目录,默认 `process.cwd()` */
|
|
308
|
+
root?: string;
|
|
309
|
+
port?: number;
|
|
310
|
+
host?: string;
|
|
311
|
+
/** false 时不监听端口,只通过 `devServer.fetch()` 访问(测试 / 嵌入) */
|
|
312
|
+
listen?: boolean;
|
|
313
|
+
/** 文件变化后的防抖时间,默认 30ms */
|
|
314
|
+
debounce?: number;
|
|
315
|
+
}
|
|
316
|
+
interface DevServer {
|
|
317
|
+
readonly url: string | undefined;
|
|
318
|
+
readonly vite: ViteDevServer;
|
|
319
|
+
/** 当前正在服务的应用 */
|
|
320
|
+
readonly app: Application | undefined;
|
|
321
|
+
fetch: (request: Request) => Promise<Response>;
|
|
322
|
+
/** 手动触发一次重载 */
|
|
323
|
+
reload: (file?: string) => Promise<ReloadResult>;
|
|
324
|
+
onReload: (listener: (result: ReloadResult) => void) => () => void;
|
|
325
|
+
/** 在应用的模块图中执行模块(命令行的 db:migrate / db:seed 使用) */
|
|
326
|
+
import: <T = any>(id: string) => Promise<T>;
|
|
327
|
+
close: () => Promise<void>;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* 纯后端项目的开发服务器:HTTP 监听只创建一次,文件变化时通过 Vite ModuleRunner
|
|
331
|
+
* 重新执行应用代码并原子替换 fetch 处理器——进程不重启、端口不断开。
|
|
332
|
+
*/
|
|
333
|
+
export declare function createDevServer(options?: DevServerOptions): Promise<DevServer>;
|
|
334
|
+
/** 构建结果记录(`.haze/build.json`),供 `vite preview` / `haze preview` 使用 */
|
|
335
|
+
interface BuildManifest extends Pick<BuildInfo, 'preset' | 'layout' | 'entry'> {
|
|
336
|
+
fullstack: boolean;
|
|
337
|
+
prefixes: string[];
|
|
338
|
+
}
|
|
339
|
+
export declare function readBuildManifest(root: string): BuildManifest;
|
|
340
|
+
interface PreviewServerOptions {
|
|
341
|
+
/** 项目根目录,默认 `process.cwd()` */
|
|
342
|
+
root?: string;
|
|
343
|
+
/** 默认 4173(与 vite preview 一致) */
|
|
344
|
+
port?: number;
|
|
345
|
+
host?: string | boolean;
|
|
346
|
+
open?: boolean;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* 本地预览构建产物(`haze preview`):按构建时的部署预设运行产物本身。
|
|
350
|
+
* 全栈项目使用项目的 vite.config.ts(等同 `vite preview`),纯后端项目使用内置配置。
|
|
351
|
+
*/
|
|
352
|
+
export declare function previewServer(options?: PreviewServerOptions): Promise<PreviewServer>;
|
|
353
|
+
interface TypegenOptions {
|
|
354
|
+
root: string;
|
|
355
|
+
srcDir: string;
|
|
356
|
+
routes: readonly RouteInfo[];
|
|
357
|
+
}
|
|
358
|
+
interface TypegenResult {
|
|
359
|
+
file: string;
|
|
360
|
+
changed: boolean;
|
|
361
|
+
configs: string[];
|
|
362
|
+
routes: string[];
|
|
363
|
+
policies: string[];
|
|
364
|
+
}
|
|
365
|
+
/** 生成文件位置(需在 tsconfig 的 include 中加入 `.haze/types/**\/*.d.ts`) */
|
|
366
|
+
export declare function typesFile(root: string): string;
|
|
367
|
+
/** 生成配置键与命名路由的类型声明(模块扩充 @hazejs/core) */
|
|
368
|
+
export declare function generateTypes({ root, srcDir, routes }: TypegenOptions): Omit<TypegenResult, 'changed'> & {
|
|
369
|
+
content: string;
|
|
370
|
+
};
|
|
371
|
+
/** 内容变化时才写入,避免触发编辑器与文件监听的无谓刷新 */
|
|
372
|
+
export declare function writeTypes(options: TypegenOptions): Promise<TypegenResult>;
|
|
373
|
+
export type { AppHost, AppHostOptions, BuildInfo, BuildManifest, BuildServerOptions, BuildServerResult, CloudflareOptions, DevServer, DevServerOptions, ExternalsOptions, HazeConfig, HazePluginApi, HazePluginOptions, Layout, Preset, PresetName, PreviewServerOptions, ReloadEvent, ReloadResult, ResolvedHazeConfig, TraceResult, TypegenOptions, TypegenResult, VercelOptions };
|