summaryrefslogtreecommitdiff
path: root/packages/integrations/deno/src/index.ts
blob: 3959e63a842e0981d45ccf9d47f6a0d38ed5f17f (plain) (blame)
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
import type { AstroAdapter, AstroIntegration } from 'astro';

interface Options {
	port?: number;
	hostname?: string;
}

export function getAdapter(args?: Options): AstroAdapter {
	return {
		name: '@astrojs/deno',
		serverEntrypoint: '@astrojs/deno/server.js',
		args: args ?? {},
		exports: ['stop', 'handle', 'start', 'running'],
	};
}

export default function createIntegration(args?: Options): AstroIntegration {
	return {
		name: '@astrojs/deno',
		hooks: {
			'astro:config:done': ({ setAdapter }) => {
				setAdapter(getAdapter(args));
			},
			'astro:build:setup': ({ vite, target }) => {
				if (target === 'server') {
					vite.resolve = vite.resolve || {};
					vite.resolve.alias = vite.resolve.alias || {};
					const alias = vite.resolve.alias as Record<string, string>;
					alias['react-dom/server'] = 'react-dom/server.browser';
					vite.ssr = {
						noExternal: true,
					};
				}
			},
		},
	};
}