Skip to content

Commit

Permalink
feat(preact): add support for devtools (#10938)
Browse files Browse the repository at this point in the history
* feat(preact): add support for devtools

* Update little-dryers-stare.md
  • Loading branch information
florian-lefebvre authored May 3, 2024
1 parent 3412535 commit fd508a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
18 changes: 18 additions & 0 deletions .changeset/little-dryers-stare.md
Original file line number Diff line number Diff line change
@@ -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 })
]
})
```
13 changes: 10 additions & 3 deletions packages/integrations/preact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,6 +59,10 @@ export default function ({ include, exclude, compat }: Options = {}): AstroInteg
updateConfig({
vite: viteConfig,
});

if (command === 'dev' && devtools) {
injectScript('page', 'import "preact/debug";');
}
},
},
};
Expand Down

0 comments on commit fd508a0

Please sign in to comment.