Skip to content

Commit

Permalink
Automatically set up Preact DevTools in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Aug 27, 2022
1 parent 2708523 commit 160e184
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-berries-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/preact': minor
---

Automatically set up Preact DevTools bridge when running `astro dev`.
4 changes: 4 additions & 0 deletions packages/integrations/preact/client-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import "preact/debug"
import clientFn from "./client.js";

export default clientFn;
1 change: 1 addition & 0 deletions packages/integrations/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"exports": {
".": "./dist/index.js",
"./client.js": "./client.js",
"./client-dev.js": "./client-dev.js",
"./server.js": "./server.js",
"./package.json": "./package.json"
},
Expand Down
15 changes: 8 additions & 7 deletions packages/integrations/preact/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AstroIntegration, AstroRenderer, ViteUserConfig } from 'astro';

function getRenderer(): AstroRenderer {
function getRenderer(development: boolean): AstroRenderer {
return {
name: '@astrojs/preact',
clientEntrypoint: '@astrojs/preact/client.js',
clientEntrypoint: development ? '@astrojs/preact/client-dev.js' : '@astrojs/preact/client.js',
serverEntrypoint: '@astrojs/preact/server.js',
jsxImportSource: 'preact',
jsxTransformOptions: async () => {
Expand All @@ -18,10 +18,10 @@ function getRenderer(): AstroRenderer {
};
}

function getCompatRenderer(): AstroRenderer {
function getCompatRenderer(development: boolean): AstroRenderer {
return {
name: '@astrojs/preact',
clientEntrypoint: '@astrojs/preact/client.js',
clientEntrypoint: development ? '@astrojs/preact/client-dev.js' : '@astrojs/preact/client.js',
serverEntrypoint: '@astrojs/preact/server.js',
jsxImportSource: 'react',
jsxTransformOptions: async () => {
Expand Down Expand Up @@ -96,9 +96,10 @@ export default function ({ compat }: { compat?: boolean } = {}): AstroIntegratio
return {
name: '@astrojs/preact',
hooks: {
'astro:config:setup': ({ addRenderer, updateConfig }) => {
if (compat) addRenderer(getCompatRenderer());
addRenderer(getRenderer());
'astro:config:setup': ({ addRenderer, updateConfig, command }) => {
const development = command === 'dev';
if (compat) addRenderer(getCompatRenderer(development));
addRenderer(getRenderer(development));
updateConfig({
vite: getViteConfiguration(compat),
});
Expand Down

0 comments on commit 160e184

Please sign in to comment.