Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically set up Preact DevTools in dev mode #4515

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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