Automatically set up Preact DevTools in dev mode (#4515)
This commit is contained in:
parent
98f242cdcd
commit
999250d651
4 changed files with 18 additions and 7 deletions
5
.changeset/brown-berries-eat.md
Normal file
5
.changeset/brown-berries-eat.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/preact': minor
|
||||
---
|
||||
|
||||
Automatically set up Preact DevTools bridge when running `astro dev`.
|
4
packages/integrations/preact/client-dev.js
Normal file
4
packages/integrations/preact/client-dev.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
import "preact/debug"
|
||||
import clientFn from "./client.js";
|
||||
|
||||
export default clientFn;
|
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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),
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue