0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00
astro/packages/integrations/preact/src/index.ts
Ben Holmes 098f6f6b06
Fix: is self accepting pt 2 module graph boogaloo (#2872)
* fix: isSelfAccepting Preact error

* refactor: add .js ext to preact entrypoints for consistency

* chore: changeset

* fix: remove ./client and ./server from preact pkg exp
2022-03-24 12:28:50 -04:00

45 lines
1 KiB
TypeScript

import { AstroIntegration } from 'astro';
function getRenderer() {
return {
name: '@astrojs/preact',
clientEntrypoint: '@astrojs/preact/client.js',
serverEntrypoint: '@astrojs/preact/server.js',
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.js', 'preact', 'preact/jsx-runtime', 'preact-render-to-string'],
exclude: ['@astrojs/preact/server.js'],
},
ssr: {
external: ['preact-render-to-string'],
},
};
}
export default function (): AstroIntegration {
return {
name: '@astrojs/preact',
hooks: {
'astro:config:setup': ({ addRenderer }) => {
addRenderer(getRenderer());
return {
vite: getViteConfiguration(),
};
},
},
};
}