summaryrefslogtreecommitdiff
path: root/packages/integrations/preact/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/preact/src')
-rw-r--r--packages/integrations/preact/src/index.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/packages/integrations/preact/src/index.ts b/packages/integrations/preact/src/index.ts
new file mode 100644
index 000000000..113284c31
--- /dev/null
+++ b/packages/integrations/preact/src/index.ts
@@ -0,0 +1,45 @@
+import { AstroIntegration } from 'astro';
+
+function getRenderer() {
+ return {
+ name: '@astrojs/preact',
+ clientEntrypoint: '@astrojs/preact/client',
+ serverEntrypoint: '@astrojs/preact/server',
+ jsxImportSource: 'preact',
+ jsxTransformOptions: async () => {
+ const {
+ default: { default: jsx },
+ // @ts-expect-error types not found
+ } = await import('@babel/plugin-transform-react-jsx');
+ return {
+ plugins: [jsx({}, { runtime: 'automatic', importSource: 'preact' })],
+ };
+ },
+ };
+}
+
+function getViteConfiguration() {
+ return {
+ optimizeDeps: {
+ include: ['@astrojs/preact/client', 'preact', 'preact/jsx-runtime', 'preact-render-to-string'],
+ exclude: ['@astrojs/preact/server'],
+ },
+ ssr: {
+ external: ['preact-render-to-string'],
+ },
+ };
+}
+
+export default function (): AstroIntegration {
+ return {
+ name: '@astrojs/preact',
+ hooks: {
+ 'astro:config:setup': ({ addRenderer }) => {
+ addRenderer(getRenderer());
+ return {
+ vite: getViteConfiguration(),
+ };
+ },
+ },
+ };
+}