From bd2ac13753e1b98cf0ff5e5a92967d518b818ee0 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 27 Oct 2021 08:18:42 -0700 Subject: [PATCH] [next] Add `preact/compat` renderer (#1668) * feat: add preact/compat entry for `@astrojs/renderer-preact` * Update index.js --- .changeset/twenty-maps-listen.md | 5 +++ .../renderers/renderer-preact/compat/index.js | 31 +++++++++++++++++++ .../renderers/renderer-preact/package.json | 1 + 3 files changed, 37 insertions(+) create mode 100644 .changeset/twenty-maps-listen.md create mode 100644 packages/renderers/renderer-preact/compat/index.js diff --git a/.changeset/twenty-maps-listen.md b/.changeset/twenty-maps-listen.md new file mode 100644 index 000000000..0f8ef3dd1 --- /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 000000000..f79998fa4 --- /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 898b77359..ebd7c61dc 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"