@hono/vite-build 1.4.0 → 1.6.0
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.
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
import { BuildOptions } from '../../base.js';
|
|
3
|
-
import '../../entry/index.js';
|
|
3
|
+
import { GetEntryContentOptions } from '../../entry/index.js';
|
|
4
4
|
|
|
5
|
-
type CloudflareWorkersBuildOptions = BuildOptions
|
|
5
|
+
type CloudflareWorkersBuildOptions = BuildOptions & Pick<GetEntryContentOptions, 'entryContentAfterHooks' | 'entryContentDefaultExportHook'>;
|
|
6
|
+
declare const defaultOptions: CloudflareWorkersBuildOptions;
|
|
6
7
|
declare const cloudflareWorkersBuildPlugin: (pluginOptions?: CloudflareWorkersBuildOptions) => Plugin;
|
|
7
8
|
|
|
8
|
-
export { CloudflareWorkersBuildOptions, cloudflareWorkersBuildPlugin as default };
|
|
9
|
+
export { CloudflareWorkersBuildOptions, cloudflareWorkersBuildPlugin as default, defaultOptions };
|
|
@@ -1,13 +1,37 @@
|
|
|
1
|
-
import buildPlugin from "../../base.js";
|
|
1
|
+
import buildPlugin, { defaultOptions as baseDefaultOptions } from "../../base.js";
|
|
2
|
+
const defaultOptions = {
|
|
3
|
+
...baseDefaultOptions,
|
|
4
|
+
entryContentAfterHooks: [
|
|
5
|
+
() => `
|
|
6
|
+
const merged = {}
|
|
7
|
+
const definedHandlers = new Set()
|
|
8
|
+
for (const [file, app] of Object.entries(modules)) {
|
|
9
|
+
for (const [key, handler] of Object.entries(app)) {
|
|
10
|
+
if (key !== 'fetch') {
|
|
11
|
+
if (definedHandlers.has(key)) {
|
|
12
|
+
throw new Error(\`Handler "\${key}" is defined in multiple entry files. Please ensure each handler (except fetch) is defined only once.\`);
|
|
13
|
+
}
|
|
14
|
+
definedHandlers.add(key)
|
|
15
|
+
merged[key] = handler
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`
|
|
20
|
+
],
|
|
21
|
+
entryContentDefaultExportHook: (appName) => `export default { ...merged, fetch: ${appName}.fetch }`
|
|
22
|
+
};
|
|
2
23
|
const cloudflareWorkersBuildPlugin = (pluginOptions) => {
|
|
3
24
|
return {
|
|
4
25
|
...buildPlugin({
|
|
5
|
-
...pluginOptions
|
|
26
|
+
...pluginOptions,
|
|
27
|
+
entryContentAfterHooks: pluginOptions?.entryContentAfterHooks ?? defaultOptions.entryContentAfterHooks,
|
|
28
|
+
entryContentDefaultExportHook: pluginOptions?.entryContentDefaultExportHook ?? defaultOptions.entryContentDefaultExportHook
|
|
6
29
|
}),
|
|
7
30
|
name: "@hono/vite-build/cloudflare-workers"
|
|
8
31
|
};
|
|
9
32
|
};
|
|
10
33
|
var cloudflare_workers_default = cloudflareWorkersBuildPlugin;
|
|
11
34
|
export {
|
|
12
|
-
cloudflare_workers_default as default
|
|
35
|
+
cloudflare_workers_default as default,
|
|
36
|
+
defaultOptions
|
|
13
37
|
};
|