Automatically set up Preact DevTools in dev mode (#4515)

This commit is contained in:
Marvin Hagemeister 2022-09-07 20:49:07 +02:00 committed by GitHub
parent 98f242cdcd
commit 999250d651
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/preact': minor
---
Automatically set up Preact DevTools bridge when running `astro dev`.

View file

@ -0,0 +1,4 @@
import "preact/debug"
import clientFn from "./client.js";
export default clientFn;

View file

@ -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"
},

View file

@ -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 () => {
@ -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 () => {
@ -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),
});