Repository: withastro/astro
File: packages/integrations/preact/src/index.ts (TypeScript)

Code before:
export const getContainerRenderer = (): AstroRenderer => getRenderer(false);

export interface Options extends Pick<VitePreactPluginOptions, 'include' | 'exclude'> {
	compat?: boolean;
	devtools?: boolean;
}

export default function ({ include, exclude, compat, devtools }: Options = {}): AstroIntegration {
	return {
		name: '@astrojs/preact',
		hooks: {
			'astro:config:setup': ({ addRenderer, updateConfig, command, injectScript }) => {
				const preactPlugin = preact({
					reactAliasesEnabled: compat ?? false,
					include,
					exclude,
					babel: {
						cwd: fileURLToPath(babelCwd),
					},
				});

				const viteConfig: ViteUserConfig = {
					optimizeDeps: {
						include: ['@astrojs/preact/server.js'],
					},
				};

				viteConfig.plugins = [preactPlugin, configEnvironmentPlugin(compat)];

				addRenderer(getRenderer(command === 'dev'));
				updateConfig({
					vite: viteConfig,
				});

				if (command === 'dev' && devtools) {
					injectScript('page', 'import "preact/debug";');
				}
			},
			'astro:config:done': ({ logger, config }) => {
				const knownJsxRenderers = ['@astrojs/react', '@astrojs/preact', '@astrojs/solid-js'];
				const enabledKnownJsxRenderers = config.integrations.filter((renderer) =>
					knownJsxRenderers.includes(renderer.name),
				);

				if (enabledKnownJsxRenderers.length > 1 && !include && !exclude) {
					logger.warn(
						'More than one JSX renderer is enabled. This will lead to unexpected behavior unless you set the `include` or `exclude` option. See https://docs.astro.build/en/guides/integrations-guide/preact/#combining-multiple-jsx-frameworks for more information.',
					);
				}
			},
		},

Review comment (performance):
```suggestion
						// Ideally would be environment config, but
						// putting it there does not result in it being optimized
						include: ['@astrojs/preact/server.js'],
```

Code after:
export const getContainerRenderer = (): AstroRenderer => getRenderer(false);

export interface Options extends Pick<VitePreactPluginOptions, 'include' | 'exclude'> {
	compat?: boolean;
	devtools?: boolean;
}

export default function ({ include, exclude, compat, devtools }: Options = {}): AstroIntegration {
	return {
		name: '@astrojs/preact',
		hooks: {
			'astro:config:setup': ({ addRenderer, updateConfig, command, injectScript }) => {
				const preactPlugin = preact({
					reactAliasesEnabled: compat ?? false,
					include,
					exclude,
					babel: {
						cwd: fileURLToPath(babelCwd),
					},
				});

				const viteConfig: ViteUserConfig = {
					optimizeDeps: {
						// Ideally would be environment config, but
						// putting it there does not result in it being optimized
						include: ['@astrojs/preact/server.js'],
					},
				};

				viteConfig.plugins = [preactPlugin, configEnvironmentPlugin(compat)];

				addRenderer(getRenderer(command === 'dev'));
				updateConfig({
					vite: viteConfig,
				});

				if (command === 'dev' && devtools) {
					injectScript('page', 'import "preact/debug";');
				}
			},
			'astro:config:done': ({ logger, config }) => {
				const knownJsxRenderers = ['@astrojs/react', '@astrojs/preact', '@astrojs/solid-js'];
				const enabledKnownJsxRenderers = config.integrations.filter((renderer) =>
					knownJsxRenderers.includes(renderer.name),
				);

				if (enabledKnownJsxRenderers.length > 1 && !include && !exclude) {
					logger.warn(
						'More than one JSX renderer is enabled. This will lead to unexpected behavior unless you set the `include` or `exclude` option. See https://docs.astro.build/en/guides/integrations-guide/preact/#combining-multiple-jsx-frameworks for more information.',
					);
				}