diff --git a/.changeset/twenty-maps-listen.md b/.changeset/twenty-maps-listen.md new file mode 100644 index 0000000000..0f8ef3dd15 --- /dev/null +++ b/.changeset/twenty-maps-listen.md @@ -0,0 +1,5 @@ +--- +'@astrojs/renderer-preact': minor +--- + +Add `@astrojs/renderer-preact/compat` entry point diff --git a/packages/renderers/renderer-preact/compat/index.js b/packages/renderers/renderer-preact/compat/index.js new file mode 100644 index 0000000000..f79998fa40 --- /dev/null +++ b/packages/renderers/renderer-preact/compat/index.js @@ -0,0 +1,31 @@ +export default { + name: '@astrojs/renderer-preact/compat', + client: '../client.js', + server: '../server.js', + jsxImportSource: 'react', + jsxTransformOptions: async () => { + const { + default: { default: jsx }, + } = await import('@babel/plugin-transform-react-jsx'); + return { + plugins: [jsx({}, { runtime: 'automatic', importSource: 'preact/compat' })], + }; + }, + viteConfig() { + return { + alias: { + react: 'preact/compat', + 'react-dom': 'preact/compat' + }, + resolve: { + dedupe: ['react', 'react-dom'], + }, + optimizeDeps: { + include: ['@astrojs/renderer-preact/client.js', 'preact/compat', 'preact/compat/jsx-runtime', 'preact-render-to-string'], + }, + ssr: { + external: ['preact-render-to-string'], + }, + }; + }, +}; diff --git a/packages/renderers/renderer-preact/package.json b/packages/renderers/renderer-preact/package.json index 898b773593..ebd7c61dcb 100644 --- a/packages/renderers/renderer-preact/package.json +++ b/packages/renderers/renderer-preact/package.json @@ -5,6 +5,7 @@ "exports": { ".": "./index.js", "./*": "./*", + "./compat": "./compat/index.js", "./client.js": "./client.js", "./server.js": "./server.js", "./package.json": "./package.json"