0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

feat(preact): add support for devtools (#10938)

* feat(preact): add support for devtools

* Update little-dryers-stare.md
This commit is contained in:
Florian Lefebvre 2024-05-03 21:21:37 +02:00 committed by GitHub
parent 3412535be4
commit fd508a0fbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 3 deletions

View file

@ -0,0 +1,18 @@
---
"@astrojs/preact": minor
---
Adds a `devtools` option
You can enable [Preact devtools](https://preactjs.github.io/preact-devtools/) in development by setting `devtools: true` in your `preact()` integration config:
```js
import { defineConfig } from "astro/config"
import preact from "@astrojs/preact"
export default defineConfig({
integrations: [
preact({ devtools: true })
]
})
```

View file

@ -12,13 +12,16 @@ function getRenderer(development: boolean): AstroRenderer {
};
}
export type Options = Pick<VitePreactPluginOptions, 'include' | 'exclude'> & { compat?: boolean };
export interface Options extends Pick<VitePreactPluginOptions, 'include' | 'exclude'> {
compat?: boolean;
devtools?: boolean;
}
export default function ({ include, exclude, compat }: Options = {}): AstroIntegration {
export default function ({ include, exclude, compat, devtools }: Options = {}): AstroIntegration {
return {
name: '@astrojs/preact',
hooks: {
'astro:config:setup': ({ addRenderer, updateConfig, command }) => {
'astro:config:setup': ({ addRenderer, updateConfig, command, injectScript }) => {
const preactPlugin = preact({
reactAliasesEnabled: compat ?? false,
include,
@ -56,6 +59,10 @@ export default function ({ include, exclude, compat }: Options = {}): AstroInteg
updateConfig({
vite: viteConfig,
});
if (command === 'dev' && devtools) {
injectScript('page', 'import "preact/debug";');
}
},
},
};