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:
parent
3412535be4
commit
fd508a0fbb
2 changed files with 28 additions and 3 deletions
18
.changeset/little-dryers-stare.md
Normal file
18
.changeset/little-dryers-stare.md
Normal 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 })
|
||||||
|
]
|
||||||
|
})
|
||||||
|
```
|
|
@ -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 {
|
return {
|
||||||
name: '@astrojs/preact',
|
name: '@astrojs/preact',
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup': ({ addRenderer, updateConfig, command }) => {
|
'astro:config:setup': ({ addRenderer, updateConfig, command, injectScript }) => {
|
||||||
const preactPlugin = preact({
|
const preactPlugin = preact({
|
||||||
reactAliasesEnabled: compat ?? false,
|
reactAliasesEnabled: compat ?? false,
|
||||||
include,
|
include,
|
||||||
|
@ -56,6 +59,10 @@ export default function ({ include, exclude, compat }: Options = {}): AstroInteg
|
||||||
updateConfig({
|
updateConfig({
|
||||||
vite: viteConfig,
|
vite: viteConfig,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (command === 'dev' && devtools) {
|
||||||
|
injectScript('page', 'import "preact/debug";');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue