@hono/vite-build 1.10.1 → 1.11.1

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +37 -0
  3. package/dist/adapter/bun/{index.d.ts → index.d.mts} +6 -6
  4. package/dist/adapter/bun/index.mjs +47 -0
  5. package/dist/adapter/cloudflare-pages/{index.d.ts → index.d.mts} +5 -5
  6. package/dist/adapter/cloudflare-pages/index.mjs +41 -0
  7. package/dist/adapter/cloudflare-workers/{index.d.ts → index.d.mts} +6 -5
  8. package/dist/adapter/cloudflare-workers/index.mjs +33 -0
  9. package/dist/adapter/deno/index.d.mts +10 -0
  10. package/dist/adapter/deno/index.mjs +21 -0
  11. package/dist/adapter/netlify-functions/{index.d.ts → index.d.mts} +5 -5
  12. package/dist/adapter/netlify-functions/index.mjs +16 -0
  13. package/dist/adapter/node/index.d.mts +19 -0
  14. package/dist/adapter/node/index.mjs +37 -0
  15. package/dist/adapter/vercel/index.d.mts +22 -0
  16. package/dist/adapter/vercel/index.mjs +170 -0
  17. package/dist/adapter/vercel/types.d.mts +276 -0
  18. package/dist/adapter/vercel/types.mjs +1 -0
  19. package/dist/base.d.mts +30 -0
  20. package/dist/base.mjs +99 -0
  21. package/dist/entry/index.d.mts +27 -0
  22. package/dist/entry/index.mjs +63 -0
  23. package/dist/entry/{serve-static.d.ts → serve-static.d.mts} +5 -4
  24. package/dist/entry/serve-static.mjs +8 -0
  25. package/dist/index.d.mts +2 -0
  26. package/dist/index.mjs +5 -0
  27. package/package.json +21 -53
  28. package/dist/adapter/bun/index.js +0 -55
  29. package/dist/adapter/cloudflare-pages/index.js +0 -53
  30. package/dist/adapter/cloudflare-workers/index.js +0 -37
  31. package/dist/adapter/deno/index.d.ts +0 -10
  32. package/dist/adapter/deno/index.js +0 -28
  33. package/dist/adapter/netlify-functions/index.js +0 -18
  34. package/dist/adapter/node/index.d.ts +0 -19
  35. package/dist/adapter/node/index.js +0 -50
  36. package/dist/adapter/vercel/index.d.ts +0 -14
  37. package/dist/adapter/vercel/index.js +0 -85
  38. package/dist/adapter/vercel/types.d.ts +0 -368
  39. package/dist/adapter/vercel/types.js +0 -0
  40. package/dist/base.d.ts +0 -29
  41. package/dist/base.js +0 -112
  42. package/dist/entry/index.d.ts +0 -26
  43. package/dist/entry/index.js +0 -69
  44. package/dist/entry/serve-static.js +0 -11
  45. package/dist/index.d.ts +0 -8
  46. package/dist/index.js +0 -6
@@ -0,0 +1,276 @@
1
+ //#region src/adapter/vercel/types.d.ts
2
+ /**
3
+ * Main configuration type for Vercel Build Output API v3.
4
+ * This type represents the root configuration object that should be output in the `.vercel/output/config.json` file.
5
+ * @see https://vercel.com/docs/build-output-api/v3/configuration
6
+ */
7
+ type VercelBuildConfigV3 = {
8
+ /** Version identifier for the Build Output API. Must be 3. */version?: 3;
9
+ /**
10
+ * Array of routing rules to handle incoming requests.
11
+ * Routes are evaluated in order, where the first matching route will be applied.
12
+ */
13
+ routes?: Route[];
14
+ /**
15
+ * Configuration for Vercel's Image Optimization feature.
16
+ * Defines how images should be optimized, cached, and served.
17
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#images
18
+ */
19
+ images?: ImagesConfig;
20
+ /**
21
+ * Custom domain wildcard configurations for internationalization.
22
+ * Maps domain names to values that can be referenced by the routes configuration.
23
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#wildcard
24
+ */
25
+ wildcard?: WildCard[];
26
+ /**
27
+ * File-specific overrides for static files in the `.vercel/output/static` directory.
28
+ * Allows overriding Content-Type headers and URL paths for static files.
29
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#overrides
30
+ */
31
+ overrides?: Record<string, Override>;
32
+ /**
33
+ * Array of file paths or glob patterns to be cached between builds.
34
+ * Only relevant when Vercel is building from source code.
35
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#cache
36
+ */
37
+ cache?: string[];
38
+ /**
39
+ * Scheduled tasks configuration for production deployments.
40
+ * Defines API routes that should be invoked on a schedule.
41
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#crons
42
+ */
43
+ crons?: Cron[];
44
+ /**
45
+ * Framework metadata for display purposes only.
46
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#framework
47
+ */
48
+ framework?: Framework;
49
+ };
50
+ /**
51
+ * Route configuration that can either be a Source route or a Handler route.
52
+ * Source routes match incoming requests, while Handler routes define special behaviors.
53
+ */
54
+ type Route = Source | Handler;
55
+ /**
56
+ * Source route configuration for matching and handling incoming requests.
57
+ * Provides detailed control over request matching and response handling.
58
+ */
59
+ type Source = {
60
+ /** Regular expression pattern to match incoming request paths */src: string; /** Path to rewrite or redirect the matched request to */
61
+ dest?: string; /** Custom HTTP headers to add to the response */
62
+ headers?: Record<string, string>; /** Array of HTTP methods this route should match */
63
+ methods?: string[]; /** When true, matching will continue even after this route matches */
64
+ continue?: boolean; /** When true, the src pattern will be matched case-sensitively */
65
+ caseSensitive?: boolean; /** Additional validation flag for route matching */
66
+ check?: boolean; /** HTTP status code to return (e.g., 308 for redirects) */
67
+ status?: number; /** Conditions that must be present in the request for the route to match */
68
+ has?: HasField; /** Conditions that must be absent from the request for the route to match */
69
+ missing?: HasField; /** Configuration for locale-based routing and redirects */
70
+ locale?: Locale; /** Raw source patterns used by middleware */
71
+ middlewareRawSrc?: string[]; /** Path to the middleware implementation file */
72
+ middlewarePath?: string; /** Mitigation action to apply to the route */
73
+ mitigate?: Mitigate; /** List of transforms to apply to the route */
74
+ transforms?: Transform[];
75
+ };
76
+ /**
77
+ * Locale configuration for internationalization routing.
78
+ * Used to configure language-specific redirects and preferences.
79
+ */
80
+ type Locale = {
81
+ /** Mapping of locale codes to their redirect destinations */redirect?: Record<string, string>; /** Name of the cookie used to store the user's locale preference */
82
+ cookie?: string;
83
+ };
84
+ /**
85
+ * Matchable value for complex route condition matching.
86
+ * Allows matching against values using various comparison operators.
87
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#source-route-matchablevalue
88
+ */
89
+ type MatchableValue = {
90
+ /** Value must equal this value */eq?: string | number; /** Value must not equal this value */
91
+ neq?: string; /** Value must be included in this array */
92
+ inc?: string[]; /** Value must not be included in this array */
93
+ ninc?: string[]; /** Value must start with this prefix */
94
+ pre?: string; /** Value must end with this suffix */
95
+ suf?: string; /** Value must match this regular expression */
96
+ re?: string; /** Value must be greater than this number */
97
+ gt?: number; /** Value must be greater than or equal to this number */
98
+ gte?: number; /** Value must be less than this number */
99
+ lt?: number; /** Value must be less than or equal to this number */
100
+ lte?: number;
101
+ };
102
+ /**
103
+ * Condition fields for route matching based on request properties.
104
+ * Used in `has` and `missing` arrays on Source routes.
105
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#source-route-hasfield
106
+ */
107
+ type HasField = Array<{
108
+ /** Identifies this as a host matching condition */type: 'host'; /** Pattern to match against the Host header */
109
+ value: string | MatchableValue;
110
+ } | {
111
+ /** Identifies the condition type: header, cookie, or query parameter */type: 'header' | 'cookie' | 'query'; /** Name of the header, cookie, or query parameter to match */
112
+ key: string; /** Optional value the field should match */
113
+ value?: string | MatchableValue;
114
+ }>;
115
+ /**
116
+ * Special handler phases for request processing.
117
+ * Defines when and how requests should be processed in the routing pipeline.
118
+ */
119
+ type HandleValue = 'rewrite' | 'filesystem' | 'resource' | 'miss' | 'hit' | 'error';
120
+ /**
121
+ * Handler route configuration for special request processing phases.
122
+ * Used to define behavior at specific points in the request lifecycle.
123
+ */
124
+ type Handler = {
125
+ /** The type of handler to process the request */handle: HandleValue; /** Optional pattern to match against the request path */
126
+ src?: string; /** Optional path to handle the request with */
127
+ dest?: string; /** HTTP status code to return in the response */
128
+ status?: number;
129
+ };
130
+ /**
131
+ * Mitigation action to apply to a route.
132
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#source-route-mitigate
133
+ */
134
+ type Mitigate = {
135
+ /** The mitigation action to apply */action: 'challenge' | 'deny';
136
+ };
137
+ /**
138
+ * Transform to apply to request or response properties on a route.
139
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#source-route-transform
140
+ */
141
+ type Transform = {
142
+ /** The target of the transform: request headers, request query, or response headers */type: 'request.headers' | 'request.query' | 'response.headers'; /** The operation to perform */
143
+ op: 'append' | 'set' | 'delete'; /** The target key for the transform (regex matching not supported) */
144
+ target: {
145
+ key: string | Omit<MatchableValue, 're'>;
146
+ }; /** Arguments for the transform operation */
147
+ args?: string | string[];
148
+ };
149
+ /**
150
+ * Supported image formats for the Image Optimization API.
151
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#images
152
+ */
153
+ type ImageFormat = 'image/avif' | 'image/webp';
154
+ /**
155
+ * Configuration for remote image sources in Image Optimization.
156
+ * Defines patterns for matching and processing external images.
157
+ */
158
+ type RemotePattern = {
159
+ /** Protocol allowed for remote images (http or https) */protocol?: 'http' | 'https'; /** Hostname pattern that remote images must match */
160
+ hostname: string; /** Optional port number for remote image URLs */
161
+ port?: string; /** Path pattern that remote image URLs must match */
162
+ pathname?: string; /** Search query pattern that remote image URLs must match */
163
+ search?: string;
164
+ };
165
+ /**
166
+ * Configuration for local image patterns in Image Optimization.
167
+ * Defines patterns for matching and processing local images.
168
+ */
169
+ type LocalPattern = {
170
+ /** Path pattern that local images must match */pathname?: string; /** Search query pattern that local image URLs must match */
171
+ search?: string;
172
+ };
173
+ /**
174
+ * Configuration for Vercel's Image Optimization feature.
175
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#images
176
+ */
177
+ type ImagesConfig = {
178
+ /** Array of allowed image widths for resizing */sizes: number[]; /** Array of allowed domains for remote images */
179
+ domains: string[]; /** Patterns for matching remote image sources */
180
+ remotePatterns?: RemotePattern[]; /** Patterns for matching local image sources */
181
+ localPatterns?: LocalPattern[]; /** Array of allowed quality values for image optimization */
182
+ qualities?: number[]; /** Minimum time (in seconds) to cache optimized images */
183
+ minimumCacheTTL?: number; /** Array of supported output formats for optimization */
184
+ formats?: ImageFormat[]; /** Whether to allow processing of SVG images (use with caution) */
185
+ dangerouslyAllowSVG?: boolean; /** Content Security Policy for optimized images */
186
+ contentSecurityPolicy?: string; /** Content-Disposition header type for image responses */
187
+ contentDispositionType?: string;
188
+ };
189
+ /**
190
+ * Configuration for custom domain wildcards.
191
+ * Used for internationalization and dynamic routing based on domains.
192
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#wildcard
193
+ */
194
+ type WildCard = {
195
+ /** Domain name to match for this wildcard configuration */domain: string; /** Value to use when this wildcard matches (available as $wildcard in routes) */
196
+ value: string;
197
+ };
198
+ /**
199
+ * Configuration for path or content-type overrides of static files.
200
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#overrides
201
+ */
202
+ type Override = {
203
+ /** URL path where the static file will be accessible */path?: string; /** Content-Type header value for the static file */
204
+ contentType?: string;
205
+ };
206
+ /**
207
+ * Configuration for scheduled tasks (Cron Jobs).
208
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#crons
209
+ */
210
+ type Cron = {
211
+ /** Path to the API route that handles the cron job */path: string; /** Cron schedule expression (e.g., "0 0 * * *" for daily at midnight) */
212
+ schedule: string;
213
+ };
214
+ /**
215
+ * Framework metadata for display purposes.
216
+ * @see https://vercel.com/docs/build-output-api/v3/configuration#framework
217
+ */
218
+ type Framework = {
219
+ /** Framework version string */version: string;
220
+ };
221
+ /**
222
+ * Base configuration for a serverless function in Vercel.
223
+ * This type represents the `.vc-config.json` configuration within a `.func` directory.
224
+ * @see https://vercel.com/docs/build-output-api/v3/primitives#serverless-function-configuration
225
+ */
226
+ type VercelServerlessFunctionConfig = {
227
+ /** Indicates the initial file where code will be executed for the Serverless Function */handler: string; /** Specifies which "runtime" will be used to execute the Serverless Function */
228
+ runtime: string; /** The amount of memory (RAM in MB) allocated to the function */
229
+ memory?: number; /** The maximum duration of the function in seconds */
230
+ maxDuration?: number; /** Map of additional environment variables available to the function */
231
+ environment?: Record<string, string>; /** The regions the function is available in */
232
+ regions?: string[]; /** Instruction set architecture the function supports */
233
+ architecture?: 'x86_64' | 'arm64'; /** Whether the custom runtime supports Lambda runtime wrappers */
234
+ supportsWrapper?: boolean; /** Whether the function supports response streaming */
235
+ supportsResponseStreaming?: boolean;
236
+ };
237
+ /**
238
+ * Node.js-specific serverless function configuration.
239
+ * Extends the base serverless function config with Node.js launcher options.
240
+ * @see https://vercel.com/docs/build-output-api/v3/primitives#nodejs-config
241
+ */
242
+ type VercelNodejsServerlessFunctionConfig = VercelServerlessFunctionConfig & {
243
+ /** Specifies which "launcher" will be used to execute the Serverless Function */launcherType: 'Nodejs'; /** Enables request and response helpers methods */
244
+ shouldAddHelpers?: boolean; /** Enables source map generation */
245
+ shouldAddSourcemapSupport?: boolean; /** AWS Handler Value for when the serverless function uses AWS Lambda syntax */
246
+ awsLambdaHandler?: string;
247
+ };
248
+ /**
249
+ * Configuration for an Edge Function in Vercel.
250
+ * This type represents the `.vc-config.json` configuration for Edge Functions.
251
+ * @see https://vercel.com/docs/build-output-api/v3/primitives#edge-function-configuration
252
+ */
253
+ type VercelEdgeFunctionConfig = {
254
+ /** Must be 'edge' to indicate this is an Edge Function */runtime: 'edge'; /** Initial file where code will be executed for the Edge Function */
255
+ entrypoint: string; /** List of environment variable names available to the Edge Function */
256
+ envVarsInUse?: string[]; /** Regions the edge function will be available in (defaults to 'all') */
257
+ regions?: 'all' | string | string[];
258
+ };
259
+ /**
260
+ * Configuration for a Prerender Function in Vercel (ISR).
261
+ * This type represents the `.prerender-config.json` configuration file.
262
+ * @see https://vercel.com/docs/build-output-api/v3/primitives#prerender-configuration-file
263
+ */
264
+ type VercelPrerenderFunctionConfig = {
265
+ /** Cache expiration time in seconds, or false to never expire */expiration: number | false; /** Group number for co-revalidating prerender assets together */
266
+ group?: number; /** Random token for Draft Mode bypass cookie (`__prerender_bypass`) */
267
+ bypassToken?: string; /** Name of the optional fallback file relative to the configuration file */
268
+ fallback?: string; /** Query string parameter names that will be cached independently */
269
+ allowQuery?: string[]; /** When true, the query string will be present on the request argument */
270
+ passQuery?: boolean; /** Initial headers to include with the build-time prerendered response */
271
+ initialHeaders?: Record<string, string>; /** Initial HTTP status code for the build-time prerendered response (default 200) */
272
+ initialStatus?: number; /** When true, expose the response body regardless of status code including errors */
273
+ exposeErrBody?: boolean;
274
+ };
275
+ //#endregion
276
+ export { VercelBuildConfigV3, VercelEdgeFunctionConfig, VercelNodejsServerlessFunctionConfig, VercelPrerenderFunctionConfig, VercelServerlessFunctionConfig };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ import { GetEntryContentOptions } from "./entry/index.mjs";
2
+ import { ConfigEnv, Plugin, UserConfig } from "vite";
3
+
4
+ //#region src/base.d.ts
5
+ type BuildOptions = {
6
+ /**
7
+ * @default ['src/index.ts', './src/index.tsx', './app/server.ts']
8
+ */
9
+ entry?: string | string[];
10
+ /**
11
+ * @default './dist'
12
+ */
13
+ output?: string;
14
+ outputDir?: string;
15
+ external?: string[];
16
+ /**
17
+ * @default true
18
+ */
19
+ minify?: boolean;
20
+ emptyOutDir?: boolean;
21
+ apply?: ((this: void, config: UserConfig, env: ConfigEnv) => boolean) | undefined;
22
+ /**
23
+ * @default 'webworker'
24
+ */
25
+ ssrTarget?: 'node' | 'webworker';
26
+ } & Omit<GetEntryContentOptions, 'entry'>;
27
+ declare const defaultOptions: Required<Omit<BuildOptions, 'entryContentAfterHooks' | 'entryContentBeforeHooks' | 'entryContentDefaultExportHook'>>;
28
+ declare const buildPlugin: (options: BuildOptions) => Plugin;
29
+ //#endregion
30
+ export { BuildOptions, buildPlugin as default, defaultOptions };
package/dist/base.mjs ADDED
@@ -0,0 +1,99 @@
1
+ import { getEntryContent } from "./entry/index.mjs";
2
+ import { builtinModules } from "module";
3
+ import { readdirSync } from "node:fs";
4
+ import { resolve } from "node:path";
5
+ //#region src/base.ts
6
+ const defaultOptions = {
7
+ entry: [
8
+ "src/index.ts",
9
+ "./src/index.tsx",
10
+ "./app/server.ts"
11
+ ],
12
+ output: "index.js",
13
+ outputDir: "./dist",
14
+ external: [],
15
+ minify: true,
16
+ emptyOutDir: false,
17
+ apply: (_config, { command, mode }) => {
18
+ if (command === "build" && mode !== "client") return true;
19
+ return false;
20
+ },
21
+ staticPaths: [],
22
+ preset: "hono",
23
+ ssrTarget: "webworker"
24
+ };
25
+ const buildPlugin = (options) => {
26
+ const virtualEntryId = "virtual:build-entry-module";
27
+ const resolvedVirtualEntryId = "\0" + virtualEntryId;
28
+ let config;
29
+ const output = options.output ?? defaultOptions.output;
30
+ const preset = options.preset ?? defaultOptions.preset;
31
+ return {
32
+ name: "@hono/vite-build",
33
+ configResolved: async (resolvedConfig) => {
34
+ config = resolvedConfig;
35
+ },
36
+ resolveId(id) {
37
+ if (id === virtualEntryId) return resolvedVirtualEntryId;
38
+ },
39
+ async load(id) {
40
+ if (id === resolvedVirtualEntryId) {
41
+ const staticPaths = options.staticPaths ?? [];
42
+ const direntPaths = [];
43
+ try {
44
+ const publicDirPaths = readdirSync(resolve(config.root, config.publicDir), { withFileTypes: true });
45
+ direntPaths.push(...publicDirPaths);
46
+ } catch {}
47
+ try {
48
+ const buildOutDirPaths = readdirSync(resolve(config.root, config.build.outDir), { withFileTypes: true });
49
+ direntPaths.push(...buildOutDirPaths);
50
+ } catch {}
51
+ const uniqueStaticPaths = /* @__PURE__ */ new Set();
52
+ direntPaths.forEach((p) => {
53
+ if (p.isDirectory()) uniqueStaticPaths.add(`/${p.name}/*`);
54
+ else {
55
+ if (p.name === output) return;
56
+ uniqueStaticPaths.add(`/${p.name}`);
57
+ }
58
+ });
59
+ staticPaths.push(...Array.from(uniqueStaticPaths));
60
+ const entry = options.entry ?? defaultOptions.entry;
61
+ return await getEntryContent({
62
+ entry: Array.isArray(entry) ? entry : [entry],
63
+ entryContentBeforeHooks: options.entryContentBeforeHooks,
64
+ entryContentAfterHooks: options.entryContentAfterHooks,
65
+ entryContentDefaultExportHook: options.entryContentDefaultExportHook,
66
+ staticPaths,
67
+ preset
68
+ });
69
+ }
70
+ },
71
+ apply: options?.apply ?? defaultOptions.apply,
72
+ config: async () => {
73
+ return {
74
+ ssr: {
75
+ external: options?.external ?? defaultOptions.external,
76
+ noExternal: true,
77
+ target: options?.ssrTarget ?? defaultOptions.ssrTarget
78
+ },
79
+ build: {
80
+ outDir: options?.outputDir ?? defaultOptions.outputDir,
81
+ emptyOutDir: options?.emptyOutDir ?? defaultOptions.emptyOutDir,
82
+ minify: options?.minify ?? defaultOptions.minify,
83
+ ssr: true,
84
+ rollupOptions: {
85
+ external: [
86
+ ...builtinModules,
87
+ /^node:/,
88
+ ...options?.external ?? defaultOptions.external
89
+ ],
90
+ input: virtualEntryId,
91
+ output: { entryFileNames: output }
92
+ }
93
+ }
94
+ };
95
+ }
96
+ };
97
+ };
98
+ //#endregion
99
+ export { buildPlugin as default, defaultOptions };
@@ -0,0 +1,27 @@
1
+ //#region src/entry/index.d.ts
2
+ type EntryContentHookOptions = {
3
+ staticPaths: string[];
4
+ };
5
+ type EntryContentHook = (appName: string, options?: EntryContentHookOptions) => string | Promise<string>;
6
+ declare const presets: readonly ["hono", "hono/tiny", "hono/quick", "@hono/hono"];
7
+ type Preset = (typeof presets)[number];
8
+ type GetEntryContentOptions = {
9
+ entry: string[];
10
+ entryContentBeforeHooks?: EntryContentHook[];
11
+ entryContentAfterHooks?: EntryContentHook[];
12
+ /**
13
+ * Explicitly specify the default export for the app. Make sure your export
14
+ * incorporates the app passed as the `appName` argument.
15
+ *
16
+ * @default `export default ${appName}`
17
+ */
18
+ entryContentDefaultExportHook?: EntryContentHook;
19
+ staticPaths?: string[];
20
+ /**
21
+ * @default `hono`
22
+ */
23
+ preset?: Preset;
24
+ };
25
+ declare const getEntryContent: (options: GetEntryContentOptions) => Promise<string>;
26
+ //#endregion
27
+ export { EntryContentHook, EntryContentHookOptions, GetEntryContentOptions, Preset, getEntryContent };
@@ -0,0 +1,63 @@
1
+ import { normalize } from "node:path";
2
+ //#region src/entry/index.ts
3
+ const presets = [
4
+ "hono",
5
+ "hono/tiny",
6
+ "hono/quick",
7
+ "@hono/hono"
8
+ ];
9
+ const normalizePaths = (paths) => {
10
+ return paths.map((p) => {
11
+ let normalizedPath = normalize(p).replace(/\\/g, "/");
12
+ if (normalizedPath.startsWith("./")) normalizedPath = normalizedPath.substring(2);
13
+ return "/" + normalizedPath;
14
+ });
15
+ };
16
+ const getEntryContent = async (options) => {
17
+ const preset = presets.includes(options.preset ?? "hono") ? options.preset ?? "hono" : (console.warn(`Invalid preset: ${options.preset}. Must be one of: ${presets.join(", ")}. Using 'hono' as default.`), "hono");
18
+ const staticPaths = options.staticPaths ?? [""];
19
+ const globStr = normalizePaths(options.entry).map((e) => `'${e}'`).join(",");
20
+ const hooksToString = async (appName, hooks) => {
21
+ if (hooks) return (await Promise.all(hooks.map((hook) => {
22
+ return hook(appName, { staticPaths });
23
+ }))).join("\n");
24
+ return "";
25
+ };
26
+ const appStr = `const modules = import.meta.glob([${globStr}], { import: 'default', eager: true })
27
+ let added = false
28
+ for (const [, app] of Object.entries(modules)) {
29
+ if (app) {
30
+ mainApp.all('*', (c) => {
31
+ let executionCtx
32
+ try {
33
+ executionCtx = c.executionCtx
34
+ } catch {}
35
+ return app.fetch(c.req.raw, c.env, executionCtx)
36
+ })
37
+ mainApp.notFound((c) => {
38
+ let executionCtx
39
+ try {
40
+ executionCtx = c.executionCtx
41
+ } catch {}
42
+ return app.fetch(c.req.raw, c.env, executionCtx)
43
+ })
44
+ added = true
45
+ }
46
+ }
47
+ if (!added) {
48
+ throw new Error("Can't import modules from [${globStr}]")
49
+ }`;
50
+ const defaultExportHook = options.entryContentDefaultExportHook ?? (() => "export default mainApp");
51
+ return `import { Hono } from '${preset}'
52
+ const mainApp = new Hono()
53
+
54
+ ${await hooksToString("mainApp", options.entryContentBeforeHooks)}
55
+
56
+ ${appStr}
57
+
58
+ ${await hooksToString("mainApp", options.entryContentAfterHooks)}
59
+
60
+ ${await hooksToString("mainApp", [defaultExportHook])}`;
61
+ };
62
+ //#endregion
63
+ export { getEntryContent };
@@ -1,7 +1,8 @@
1
+ //#region src/entry/serve-static.d.ts
1
2
  type ServeStaticHookOptions = {
2
- filePaths?: string[];
3
- root?: string;
3
+ filePaths?: string[];
4
+ root?: string;
4
5
  };
5
6
  declare const serveStaticHook: (appName: string, options: ServeStaticHookOptions) => string;
6
-
7
- export { serveStaticHook };
7
+ //#endregion
8
+ export { serveStaticHook };
@@ -0,0 +1,8 @@
1
+ //#region src/entry/serve-static.ts
2
+ const serveStaticHook = (appName, options) => {
3
+ let code = "";
4
+ for (const path of options.filePaths ?? []) code += `${appName}.use('${path}', serveStatic({ root: '${options.root ?? "./"}' }))\n`;
5
+ return code;
6
+ };
7
+ //#endregion
8
+ export { serveStaticHook };
@@ -0,0 +1,2 @@
1
+ import buildPlugin, { defaultOptions } from "./base.mjs";
2
+ export { buildPlugin as default, defaultOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import buildPlugin, { defaultOptions } from "./base.mjs";
2
+ //#region src/index.ts
3
+ var src_default = buildPlugin;
4
+ //#endregion
5
+ export { src_default as default, defaultOptions };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@hono/vite-build",
3
3
  "description": "Vite plugin to build your Hono app",
4
- "version": "1.10.1",
5
- "types": "dist/index.d.ts",
6
- "module": "dist/index.js",
4
+ "version": "1.11.1",
5
+ "types": "dist/index.d.mts",
6
+ "module": "dist/index.mjs",
7
7
  "type": "module",
8
8
  "scripts": {
9
9
  "test": "vitest --run",
10
- "build": "rimraf dist && tsup && publint",
11
- "watch": "tsup --watch",
10
+ "build": "yarn run -T tsdown",
11
+ "watch": "yarn run -T tsdown --watch",
12
12
  "prerelease": "yarn build",
13
13
  "release": "yarn publish"
14
14
  },
@@ -17,64 +17,36 @@
17
17
  ],
18
18
  "exports": {
19
19
  ".": {
20
- "types": "./dist/index.d.ts",
21
- "import": "./dist/index.js"
20
+ "types": "./dist/index.d.mts",
21
+ "import": "./dist/index.mjs"
22
22
  },
23
23
  "./bun": {
24
- "types": "./dist/adapter/bun/index.d.ts",
25
- "import": "./dist/adapter/bun/index.js"
24
+ "types": "./dist/adapter/bun/index.d.mts",
25
+ "import": "./dist/adapter/bun/index.mjs"
26
26
  },
27
27
  "./node": {
28
- "types": "./dist/adapter/node/index.d.ts",
29
- "import": "./dist/adapter/node/index.js"
28
+ "types": "./dist/adapter/node/index.d.mts",
29
+ "import": "./dist/adapter/node/index.mjs"
30
30
  },
31
31
  "./cloudflare-pages": {
32
- "types": "./dist/adapter/cloudflare-pages/index.d.ts",
33
- "import": "./dist/adapter/cloudflare-pages/index.js"
32
+ "types": "./dist/adapter/cloudflare-pages/index.d.mts",
33
+ "import": "./dist/adapter/cloudflare-pages/index.mjs"
34
34
  },
35
35
  "./cloudflare-workers": {
36
- "types": "./dist/adapter/cloudflare-workers/index.d.ts",
37
- "import": "./dist/adapter/cloudflare-workers/index.js"
36
+ "types": "./dist/adapter/cloudflare-workers/index.d.mts",
37
+ "import": "./dist/adapter/cloudflare-workers/index.mjs"
38
38
  },
39
39
  "./netlify-functions": {
40
- "types": "./dist/adapter/netlify-functions/index.d.ts",
41
- "import": "./dist/adapter/netlify-functions/index.js"
40
+ "types": "./dist/adapter/netlify-functions/index.d.mts",
41
+ "import": "./dist/adapter/netlify-functions/index.mjs"
42
42
  },
43
43
  "./deno": {
44
- "types": "./dist/adapter/deno/index.d.ts",
45
- "import": "./dist/adapter/deno/index.js"
44
+ "types": "./dist/adapter/deno/index.d.mts",
45
+ "import": "./dist/adapter/deno/index.mjs"
46
46
  },
47
47
  "./vercel": {
48
- "types": "./dist/adapter/vercel/index.d.ts",
49
- "import": "./dist/adapter/vercel/index.js"
50
- }
51
- },
52
- "typesVersions": {
53
- "*": {
54
- "types": [
55
- "./dist/types"
56
- ],
57
- "bun": [
58
- "./dist/adapter/bun/index.d.ts"
59
- ],
60
- "node": [
61
- "./dist/adapter/node/index.d.ts"
62
- ],
63
- "cloudflare-pages": [
64
- "./dist/adapter/cloudflare-pages/index.d.ts"
65
- ],
66
- "cloudflare-workers": [
67
- "./dist/adapter/cloudflare-workers/index.d.ts"
68
- ],
69
- "netlify-functions": [
70
- "./dist/adapter/netlify-functions/index.d.ts"
71
- ],
72
- "deno": [
73
- "./dist/adapter/deno/index.d.ts"
74
- ],
75
- "vercel": [
76
- "./dist/adapter/vercel/index.d.ts"
77
- ]
48
+ "types": "./dist/adapter/vercel/index.d.mts",
49
+ "import": "./dist/adapter/vercel/index.mjs"
78
50
  }
79
51
  },
80
52
  "author": "Yusuke Wada <yusuke@kamawada.com> (https://github.com/yusukebe)",
@@ -95,11 +67,7 @@
95
67
  "devDependencies": {
96
68
  "@hono/node-server": "^1.19.11",
97
69
  "@types/node": "^24.10.0",
98
- "glob": "^10.3.10",
99
70
  "hono": "^4.6.12",
100
- "publint": "^0.1.12",
101
- "rimraf": "^5.0.1",
102
- "tsup": "^7.2.0",
103
71
  "vite": "^6.1.1",
104
72
  "vitest": "^2.1.1"
105
73
  },